@pdfslick/solid 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -70
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<br><br>
|
|
6
6
|
<div align="center">
|
|
7
|
-
View and Interact with
|
|
7
|
+
View and Interact with PDF documents in SolidJS apps
|
|
8
8
|
<br><br>
|
|
9
9
|
|
|
10
10
|
[Getting Started](https://pdfslick.dev/docs) | [Examples](https://pdfslick.dev/examples)
|
|
@@ -15,69 +15,12 @@ View and Interact with PDFs in React and SolidJS apps
|
|
|
15
15
|
---
|
|
16
16
|
<br>
|
|
17
17
|
|
|
18
|
-
PDFSlick is a library
|
|
18
|
+
PDFSlick for Solid is a library which enables viewing of and interaction with PDF documents in SolidJS apps.
|
|
19
19
|
It's build on top of Mozilla's [PDF.js](https://github.com/mozilla/pdf.js), and utilises [Zustand](https://github.com/pmndrs/zustand) to provide a reactive store for the loaded documents.
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Getting started with PDFSlick for SolidJS
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## Core Concepts
|
|
26
|
-
|
|
27
|
-
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.
|
|
28
|
-
|
|
29
|
-
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.
|
|
30
|
-
|
|
31
|
-
## Getting Started with React
|
|
32
|
-
|
|
33
|
-
To get started with React run:
|
|
34
|
-
```shell
|
|
35
|
-
npm install @pdfslick/react
|
|
36
|
-
# yarn add @pdfslick/react
|
|
37
|
-
# pnpm add @pdfslick/react
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
You can start using PDFSlick with the `usePDFSlick()` hook, like with the following basic example:
|
|
41
|
-
```jsx
|
|
42
|
-
import { usePDFSlick } from "@pdfslick/react";
|
|
43
|
-
import PDFNavigation from "./PDFNavigation";
|
|
44
|
-
|
|
45
|
-
import "@pdfslick/react/dist/pdf_viewer.css";
|
|
46
|
-
|
|
47
|
-
type PDFViewerAppProps = {
|
|
48
|
-
pdfFilePath: string;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const SimplePDFViewer = ({ pdfFilePath }: PDFViewerAppProps) => {
|
|
52
|
-
const { viewerRef, usePDFSlickStore, PDFSlickViewer } = usePDFSlick(pdfFilePath, {
|
|
53
|
-
singlePageViewer: true,
|
|
54
|
-
scaleValue: "page-fit"
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<div className="absolute inset-0 bg-slate-200/70 pdfSlick">
|
|
59
|
-
<div className="flex-1 relative h-full">
|
|
60
|
-
<PDFSlickViewer {...{ viewerRef, usePDFSlickStore }} />
|
|
61
|
-
<PDFNavigation {...{ usePDFSlickStore }} />
|
|
62
|
-
</div>
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default SimplePDFViewer;
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
Provided with the PDF Document path and options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
|
|
71
|
-
- `PDFSlickViewer` — the PDF Viewer component used for viewing the PDF document
|
|
72
|
-
- `viewerRef` — a `RefCallback` that is provided as a prop to the `<PDFSlickViewer />` component
|
|
73
|
-
- `usePDFSlickStore` — a hook to the PDFSlick store
|
|
74
|
-
|
|
75
|
-
<br><br>
|
|
76
|
-
[Read more about using PDFSlick with React](https://pdfslick.dev/docs/react) | [Checkout the React Examples](./apps/web/examples)
|
|
77
|
-
|
|
78
|
-
## SolidJS
|
|
79
|
-
|
|
80
|
-
To get started with PDFSlick for SolidJS React run:
|
|
23
|
+
To get started with PDFSlick for SolidJS run:
|
|
81
24
|
```shell
|
|
82
25
|
npm install @pdfslick/solid
|
|
83
26
|
# yarn add @pdfslick/solid
|
|
@@ -88,32 +31,57 @@ You can start using PDFSlick with the `usePDFSlick()` hook, like with the follow
|
|
|
88
31
|
```jsx
|
|
89
32
|
import { Component, createSignal } from "solid-js";
|
|
90
33
|
import { usePDFSlick } from "@pdfslick/solid";
|
|
34
|
+
import PDFNavigation from "./yourcomponents/PDFNavigation";
|
|
35
|
+
|
|
36
|
+
//
|
|
37
|
+
// It is required to include PDFSlick's CSS styles once
|
|
38
|
+
// you can do it in your main `App.tsx` for example
|
|
39
|
+
//
|
|
40
|
+
import "@pdfslick/solid/dist/pdf_viewer.css";
|
|
91
41
|
|
|
92
|
-
type
|
|
42
|
+
type PDFViewerComponentProps = {
|
|
93
43
|
pdfFilePath: string;
|
|
94
44
|
};
|
|
95
45
|
|
|
96
|
-
const
|
|
46
|
+
const PDFViewerComponent: Component<PDFViewerComponentProps> = ({ pdfFilePath }) => {
|
|
97
47
|
const { viewerRef, pdfSlickStore: store, PDFSlickViewer } =
|
|
98
48
|
usePDFSlick(pdfFilePath);
|
|
99
49
|
|
|
100
50
|
return (
|
|
101
|
-
<div class="absolute inset-0
|
|
51
|
+
<div class="absolute inset-0 flex flex-col pdfSlick">
|
|
102
52
|
<div class="flex-1 relative h-full">
|
|
103
53
|
<PDFSlickViewer {...{ store, viewerRef }} />
|
|
54
|
+
|
|
55
|
+
{/*
|
|
56
|
+
Pass PDFSlick's store to your custom components (like the `<PDFNavigation />` below) —
|
|
57
|
+
Toolbars, Sidebars, components which render thumbnails etc.
|
|
58
|
+
and use it as here to get and react on
|
|
59
|
+
PDF document and viewer properties and changes
|
|
60
|
+
*/}
|
|
61
|
+
<PDFNavigation {...{ store }} />
|
|
62
|
+
|
|
63
|
+
{/*
|
|
64
|
+
PDFSlick's store values automatically update
|
|
65
|
+
*/}
|
|
66
|
+
<div className="absolute w-full top-0 left-0">
|
|
67
|
+
<p>Current scale: {store.scale}</p>
|
|
68
|
+
<p>Current page number: {store.pageNumber}</p>
|
|
69
|
+
<p>Total number of pages: {store.numPages}</p>
|
|
70
|
+
</div>
|
|
104
71
|
</div>
|
|
105
72
|
</div>
|
|
106
73
|
);
|
|
107
74
|
};
|
|
108
75
|
|
|
109
|
-
export default
|
|
76
|
+
export default PDFViewerComponent;
|
|
110
77
|
```
|
|
111
78
|
|
|
112
79
|
Provided with the PDF Document path and options object, the `usePDFSlick()` hook returns an object consisting (among the other things) of:
|
|
113
|
-
- `PDFSlickViewer`
|
|
114
|
-
- `viewerRef`
|
|
115
|
-
- `pdfSlickStore`
|
|
80
|
+
- `PDFSlickViewer` is the PDF Viewer component used for viewing the PDF document
|
|
81
|
+
- `viewerRef` is the `ref` callback that is provided as a prop to the `<PDFSlickViewer />` component
|
|
82
|
+
- `pdfSlickStore` is the PDFSlick store
|
|
116
83
|
|
|
117
|
-
<br
|
|
118
|
-
|
|
84
|
+
<br>
|
|
85
|
+
|
|
86
|
+
[More on using PDFSlick with Solid](https://pdfslick.dev/docs/solid) | [Checkout the SolidJS Examples](./apps/solidweb/src/examples)
|
|
119
87
|
|