PDFSlick — view and interact with PDF documents in your React and SolidJS apps.
npm install @pdfslick/core---
PDFSlick is a library which enables viewing of and interaction with PDF documents in React and SolidJS apps.
It's build on top of Mozilla's PDF.js, and utilises Zustand to provide a reactive store for the loaded documents.
The core of PDFSlick is within the @pdfslick/core package. It wraps PDF.js's functionality and links it to the store. This @pdfslick/core package is the basis for the React and SolidJS packages, which additionally transform the store and make it suitable for the adequate library, as well as providing components for the PDF viewer and thumbnails.
Depending on your needs, at this you might find it useful to continue with learning more about using PDFSlick with React and SolidJS respsectivelly. However, if really interested you can learn more about using PDFSlick's @pdfslick/core package with Vanilla JS apps and with libraries other than React and SolidJS in the sections below.
To get started with React run:
``shell`
npm install @pdfslick/reactyarn add @pdfslick/react
pnpm add @pdfslick/react
You can start using PDFSlick with the usePDFSlick() hook, like with the following basic example:
`jsx
import { usePDFSlick } from "@pdfslick/react";
import PDFNavigation from "./yourcomponents/PDFNavigation";
//
// It is required to include PDFSlick's CSS styles once
// you can do it in your main App.tsx for example
//
import "@pdfslick/react/dist/pdf_viewer.css";
type PDFViewerComponentProps = {
pdfFilePath: string,
};
const PDFViewerComponent = ({ pdfFilePath }: PDFViewerComponent) => {
const { viewerRef, usePDFSlickStore, PDFSlickViewer } = usePDFSlick(
pdfFilePath,
{
scaleValue: "page-fit",
}
);
/*
Access the store with usePDFSlickStore() hook — you can pass is
as a prop to other components (like with below)
Toolbars, Sidebars, components which render thumbnails etc.
and use it as here to get and react on
PDF document's and viewer's properties and changes
*/
const scale = usePDFSlickStore((s) => s.scale);
const numPages = usePDFSlickStore((s) => s.numPages);
const pageNumber = usePDFSlickStore((s) => s.pageNumber);
return (
{/*
Pass PDFSlick's store to your custom components
*/}
{/*
PDFSlick's store values automatically update
*/}
Current scale: {scale}
Current page number: {pageNumber}
Total number of pages: {numPages}
export default PDFViewerComponent;
`
Provided with the PDF Document path and PDFSlick options object, the usePDFSlick() hook returns an object consisting (among the other things) of:
- PDFSlickViewer is the PDF Viewer component used for viewing the PDF documentviewerRef
- is the ref callback that is provided as a prop to the componentusePDFSlickStore
- enables using PDFSlick store within your React components
More on using PDFSlick with React | Checkout the React Examples
To get started with PDFSlick for SolidJS run:
`shell`
npm install @pdfslick/solidyarn add @pdfslick/solid
pnpm add @pdfslick/solid
You can start using PDFSlick with the usePDFSlick() hook, like with the following basic example:
`jsx
import { Component, createSignal } from "solid-js";
import { usePDFSlick } from "@pdfslick/solid";
import PDFNavigation from "./yourcomponents/PDFNavigation";
//
// It is required to include PDFSlick's CSS styles once
// you can do it in your main App.tsx for example
//
import "@pdfslick/solid/dist/pdf_viewer.css";
type PDFViewerComponentProps = {
pdfFilePath: string,
};
const PDFViewerComponent: Component
pdfFilePath,
}) => {
const {
viewerRef,
pdfSlickStore: store,
PDFSlickViewer,
} = usePDFSlick(pdfFilePath);
return (
{/*
Pass PDFSlick's store to your custom components (like the below) —
Toolbars, Sidebars, components which render thumbnails etc.
and use it as here to get and react on
PDF document and viewer properties and changes
*/}
{/*
PDFSlick's store values automatically update
*/}
Current scale: {store.scale}
Current page number: {store.pageNumber}
Total number of pages: {store.numPages}
export default PDFViewerComponent;
`
Provided with the PDF Document path and options object, the usePDFSlick() hook returns an object consisting (among the other things) of:
- PDFSlickViewer is the PDF Viewer component used for viewing the PDF documentviewerRef
- is the ref callback that is provided as a prop to the componentpdfSlickStore` is the PDFSlick store
-
More on using PDFSlick with Solid | Checkout the SolidJS Examples
Learn more about PDFSlick | Checkout the Examples
PDFSlick was conceived and developed, and is currently maintained by Vancho Stojkov, who embarked on this project with the vision of simplifying PDF integration for modern web frameworks, leveraging the power of PDF.js while providing a developer-friendly API.
- Vane Kosturanov for designing the logo
- VS Code Icons for the icons used throughout the examples