react-web-pdf-editor 0.1.3 → 0.1.5
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 +21 -5
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
View and edit PDFs in the browser with React. Open a file, annotate it, change the page order, and export a new PDF. Rendering uses [PDF.js](https://mozilla.github.io/pdf.js/). Export uses [pdf-lib](https://pdf-lib.js.org/).
|
|
4
4
|
|
|
5
|
+
[Live demos](https://react-web-pdf-editor-demo.vercel.app/) open the same sample PDF three ways: a direct client import, a browser-only dynamic import, and a toolbar you render yourself.
|
|
6
|
+
|
|
5
7
|
The editor includes:
|
|
6
8
|
|
|
7
9
|
- Continuous page viewing, zoom, and in-document search
|
|
@@ -13,6 +15,18 @@ The editor includes:
|
|
|
13
15
|
|
|
14
16
|
Annotations stay in memory until you export. Changing the `file` prop starts a fresh document and clears them.
|
|
15
17
|
|
|
18
|
+
## Demos
|
|
19
|
+
|
|
20
|
+
The [examples site](https://react-web-pdf-editor-demo.vercel.app/) loads `/file/compressed.tracemonkey-pldi-09.pdf` on every route. Replace that URL with your own PDF when you copy the code.
|
|
21
|
+
|
|
22
|
+
| Example | Live page | What it shows |
|
|
23
|
+
| --- | --- | --- |
|
|
24
|
+
| Quick start | [/quick-start](https://react-web-pdf-editor-demo.vercel.app/quick-start) | A client component imports `PdfEditor`, loads the stylesheet, and opens a PDF with a document name and a full-viewport height (`file`, `name`, and `style`). |
|
|
25
|
+
| Basic demo | [/basic-demo](https://react-web-pdf-editor-demo.vercel.app/basic-demo) | `next/dynamic` loads `PdfEditor` with `ssr: false`, so canvas, `window`, and the PDF.js worker run in the browser. Safe to render from an App Router page. |
|
|
26
|
+
| Custom toolbar | [/custom](https://react-web-pdf-editor-demo.vercel.app/custom) | A `toolbar` render prop. The bar renames the document, switches tools, and exports through `ToolbarApi`. |
|
|
27
|
+
|
|
28
|
+
The custom toolbar covers select, draw, highlight, text, image, and signature, plus undo, redo, zoom, pages, search, and export. The [quick start](#quick-start), [Next.js](#nextjs), and [custom toolbar](#custom-toolbar) sections below are those same patterns.
|
|
29
|
+
|
|
16
30
|
## Install
|
|
17
31
|
|
|
18
32
|
```bash
|
|
@@ -30,6 +44,8 @@ import "react-web-pdf-editor/styles.css";
|
|
|
30
44
|
|
|
31
45
|
## Quick start
|
|
32
46
|
|
|
47
|
+
This is the [quick start demo](https://react-web-pdf-editor-demo.vercel.app/quick-start): a client component that imports `PdfEditor` directly.
|
|
48
|
+
|
|
33
49
|
```tsx
|
|
34
50
|
import { PdfEditor } from "react-web-pdf-editor";
|
|
35
51
|
import "react-web-pdf-editor/styles.css";
|
|
@@ -240,7 +256,7 @@ onExport={(blob) => {
|
|
|
240
256
|
|
|
241
257
|
## Custom toolbar
|
|
242
258
|
|
|
243
|
-
`toolbar` receives a `ToolbarApi`. `showToolbar={false}` removes the bar entirely.
|
|
259
|
+
`toolbar` receives a `ToolbarApi`. `showToolbar={false}` removes the bar entirely. The [custom toolbar demo](https://react-web-pdf-editor-demo.vercel.app/custom) is a full bar on this API: select, draw, highlight, text, image, and signature, plus undo, redo, zoom, pages, search, and export.
|
|
244
260
|
|
|
245
261
|
```tsx
|
|
246
262
|
import { PdfEditor, Toolbar } from "react-web-pdf-editor";
|
|
@@ -357,13 +373,13 @@ Keep the default thumbnails by rendering `PagesSidebar`:
|
|
|
357
373
|
|
|
358
374
|
## Workers
|
|
359
375
|
|
|
360
|
-
PDF.js renders pages on a worker. The default worker URL is a version-matched file on unpkg:
|
|
376
|
+
PDF.js renders pages on a worker. The default is the legacy build, because that worker runs in its own thread and does not see polyfills on the page. The URL is a version-matched file on unpkg:
|
|
361
377
|
|
|
362
378
|
```text
|
|
363
|
-
https://unpkg.com/pdfjs-dist@<version>/build/pdf.worker.min.mjs
|
|
379
|
+
https://unpkg.com/pdfjs-dist@<version>/legacy/build/pdf.worker.min.mjs
|
|
364
380
|
```
|
|
365
381
|
|
|
366
|
-
Self-host that file and pass `workerSrc` when the CDN is blocked or you want the worker on your own origin. Copy it from `node_modules/pdfjs-dist/build/pdf.worker.min.mjs`.
|
|
382
|
+
Self-host that file and pass `workerSrc` when the CDN is blocked or you want the worker on your own origin. Copy it from `node_modules/pdfjs-dist/legacy/build/pdf.worker.min.mjs`. A custom `workerSrc` has to be that legacy worker.
|
|
367
383
|
|
|
368
384
|
```tsx
|
|
369
385
|
<PdfEditor file={file} workerSrc="/pdf.worker.min.mjs" />
|
|
@@ -381,7 +397,7 @@ Export uses a second worker shipped with this package. Vite, Webpack, and other
|
|
|
381
397
|
|
|
382
398
|
## Next.js
|
|
383
399
|
|
|
384
|
-
Load the editor in the browser. The package talks to workers, canvas, and `window` during render.
|
|
400
|
+
Load the editor in the browser. The package talks to workers, canvas, and `window` during render. This is the [basic demo](https://react-web-pdf-editor-demo.vercel.app/basic-demo). A direct import from a client component, without `next/dynamic`, is the [quick start demo](https://react-web-pdf-editor-demo.vercel.app/quick-start).
|
|
385
401
|
|
|
386
402
|
```tsx
|
|
387
403
|
"use client";
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pdfLib = require('pdf-lib');
|
|
4
|
-
var
|
|
4
|
+
var pdf_mjs = require('pdfjs-dist/legacy/build/pdf.mjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
@@ -620,9 +620,9 @@ var init_exportPdf = __esm({
|
|
|
620
620
|
HIGHLIGHT_OPACITY = 0.38;
|
|
621
621
|
}
|
|
622
622
|
});
|
|
623
|
-
var DEFAULT_WORKER_SRC = `https://unpkg.com/pdfjs-dist@${
|
|
623
|
+
var DEFAULT_WORKER_SRC = `https://unpkg.com/pdfjs-dist@${pdf_mjs.version}/legacy/build/pdf.worker.min.mjs`;
|
|
624
624
|
function configurePdfWorker(workerSrc) {
|
|
625
|
-
|
|
625
|
+
pdf_mjs.GlobalWorkerOptions.workerSrc = workerSrc ?? DEFAULT_WORKER_SRC;
|
|
626
626
|
}
|
|
627
627
|
var SWATCHES = ["#facc15", "#4ade80", "#38bdf8", "#f472b6", "#fb923c"];
|
|
628
628
|
function sameColor(a, b) {
|
|
@@ -3357,10 +3357,10 @@ function PdfPage({
|
|
|
3357
3357
|
canvas.style.height = `${cssHeight}px`;
|
|
3358
3358
|
context.drawImage(offscreen, 0, 0);
|
|
3359
3359
|
textLayerDiv.replaceChildren();
|
|
3360
|
-
|
|
3360
|
+
pdf_mjs.setLayerDimensions(textLayerDiv, viewport);
|
|
3361
3361
|
textLayerDiv.style.setProperty("--scale-factor", String(viewport.scale));
|
|
3362
3362
|
textLayerDiv.style.setProperty("--total-scale-factor", String(viewport.scale));
|
|
3363
|
-
textLayer = new
|
|
3363
|
+
textLayer = new pdf_mjs.TextLayer({
|
|
3364
3364
|
textContentSource: page.streamTextContent(),
|
|
3365
3365
|
container: textLayerDiv,
|
|
3366
3366
|
viewport
|
|
@@ -7181,7 +7181,7 @@ function usePdfDocument(file, workerSrc) {
|
|
|
7181
7181
|
setLoadPhase("loading");
|
|
7182
7182
|
setDownloadProgress(null);
|
|
7183
7183
|
}
|
|
7184
|
-
loadingTask =
|
|
7184
|
+
loadingTask = pdf_mjs.getDocument(source);
|
|
7185
7185
|
const incoming = await loadingTask.promise;
|
|
7186
7186
|
if (cancelled) {
|
|
7187
7187
|
await incoming.destroy();
|