Skip to content

Commit d4cdc19

Browse files
authored
Merge pull request #6 from missing-elements/docs/pdfjs-viewer-4.5
Update pdfjs-viewer docs for v4.5.0
2 parents a5e7192 + 8d0b8b7 commit d4cdc19

4 files changed

Lines changed: 28 additions & 13 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"@11ty/eleventy-plugin-syntaxhighlight": "5.0.2"
1313
},
1414
"dependencies": {
15-
"@missing-elements/pdfjs-viewer": "4.4.2"
15+
"@missing-elements/pdfjs-viewer": "4.5.0"
1616
}
1717
}

‎pnpm-lock.yaml‎

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/_data/pdfjsAttributes.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default [
8989
{
9090
name: "assets-base",
9191
group: "files",
92-
description: "Folder URL of the package's `dist` files: the five runtime files and the PDF.js data folders. Needed when your bundler doesn't emit the files, when a bundled app's documents need the data, or to load everything from a CDN. See [Bundlers](#bundlers-and-assets-base).",
92+
description: "Folder URL of the package's `dist` files: the runtime files and the PDF.js data folders. Needed when your bundler doesn't emit the files, when a bundled app's documents need the data, or to load everything from a CDN. See [Bundlers](#bundlers-and-assets-base).",
9393
default: "Folder of `pdfjs-viewer-element.js`",
9494
update: "init",
9595
},
@@ -100,6 +100,13 @@ export default [
100100
default: "Bundled `pdf.worker.min.mjs`",
101101
update: "load",
102102
},
103+
{
104+
name: "renderer-src",
105+
group: "files",
106+
description: "PDF.js renderer worker module URL, used only when [worker rendering](#worker) is on. Must match the bundled PDF.js version.",
107+
default: "Bundled `pdf.renderer.min.mjs`",
108+
update: "load",
109+
},
103110
{
104111
name: "pdfjs-lib-src",
105112
group: "files",

‎src/pdfjs-viewer/index.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ If your page has a Content Security Policy, allow the locale file's origin in `c
209209

210210
## Hosting
211211

212-
The element loads the viewer at runtime from five files next to `pdfjs-viewer-element.js` in the package's `dist` folder: `viewer.mjs`, `pdf.mjs`, `pdf.worker.min.mjs`, `viewer.css` and `paper-and-ink.css`. All of them must come from the same release as the element. The [data some PDFs need](#cmaps-fonts-and-other-resources) sits beside them.
212+
The element loads the viewer at runtime from five files next to `pdfjs-viewer-element.js` in the package's `dist` folder: `viewer.mjs`, `pdf.mjs`, `pdf.worker.min.mjs`, `viewer.css` and `paper-and-ink.css`. All of them must come from the same release as the element. The [data some PDFs need](#cmaps-fonts-and-other-resources) sits beside them. With [worker rendering](#worker) on, the viewer also loads `pdf.renderer.min.mjs` from the same folder.
213213

214214
### Bundlers and `assets-base`
215215

@@ -276,6 +276,8 @@ If your pipeline renames files, for example with content hashes, set each runtim
276276
</pdfjs-viewer-element>
277277
```
278278
279+
If you turn on [worker rendering](#worker), set `renderer-src` too.
280+
279281
The data folders are looked up next to `viewer-src`, and the scripting sandbox next to `pdfjs-lib-src`. Copy `cmaps/`, `standard_fonts/`, `wasm/`, `iccs/`, `images/` and `pdf.sandbox.mjs` from `dist` there and keep their names unhashed, because PDF.js loads them by name. Or point the [resource attributes](#pdf-js-resources) somewhere else.
280282
281283
### Worker
@@ -291,6 +293,10 @@ Set `worker-src` only to serve the worker from somewhere else, and use the match
291293
</pdfjs-viewer-element>
292294
```
293295
296+
PDF.js can also draw pages in a second worker, off the main thread. This is off by default. To turn it on, call [`setViewerOptions({ disableWorkerRendering: false })`](#setvieweroptions-options) right after you add the element.
297+
298+
That worker runs the bundled `pdf.renderer.min.mjs`. PDF.js starts it from a `blob:` URL too, so it needs the same Content Security Policy as the main worker. Set `renderer-src` only to serve the file from somewhere else, and use the matching PDF.js version ({{ pdfjsViewer.pdfjsVersion }}). If the worker can't start, PDF.js logs a "Renderer worker disabled" warning and draws on the main thread.
299+
294300
### CMaps, fonts and other resources
295301
296302
Most PDFs render with just the viewer files. Some need extra PDF.js data: CMaps for some CJK text, standard fonts for non-embedded base fonts, WASM decoders for JBIG2, CCITT and JPEG 2000 images, ICC color profiles, annotation icons, and the scripting sandbox for PDFs with JavaScript. All of it ships in the package and loads only for documents that need it.
@@ -350,7 +356,8 @@ import type { PdfjsViewerElement } from '@missing-elements/pdfjs-viewer'
350356
type PdfjsViewerAttribute =
351357
| 'src' | 'page' | 'zoom' | 'pagemode' | 'search' | 'phrase'
352358
| 'viewer-css-theme' | 'locale' | 'locale-src-template' | 'iframe-title'
353-
| 'assets-base' | 'worker-src' | 'pdfjs-lib-src' | 'viewer-src' | 'viewer-css-src' | 'theme-css-src'
359+
| 'assets-base' | 'worker-src' | 'renderer-src' | 'pdfjs-lib-src'
360+
| 'viewer-src' | 'viewer-css-src' | 'theme-css-src'
354361
| 'c-map-url' | 'standard-font-data-url' | 'wasm-url' | 'icc-url'
355362
| 'image-resources-path' | 'sandbox-bundle-src'
356363

@@ -498,6 +505,7 @@ import '@missing-elements/pdfjs-viewer' // was: import 'pdfjs-viewer-element'
498505
499506
If you're coming from an older version:
500507
508+
- **From 4.4.2 or earlier:** version 4.5 moved from PDF.js 6.4 to 6.5. If you set `worker-src`, point it at `pdfjs-dist@{{ pdfjsViewer.pdfjsVersion }}`. TypeScript now rejects a bare `Uint8Array` in `viewerApp.open()`, which already failed at runtime. Pass `{ data }`, as in [Open a PDF from bytes](#open-a-pdf-from-bytes).
501509
- **From 4.4.0 or earlier:** if your Content Security Policy allows `blob:` in `connect-src` only for locales, you can remove it.
502510
- **From 4.3 or earlier:** if you worked around region locales with a lowercase code and lowercase locale folders, rename the folders back to their original case, such as `pt-BR`, and use any case in `locale`. PDF JavaScript now runs; see [PDF.js resources](#cmaps-fonts-and-other-resources) to turn it off. Absolute resource URLs keep working, and `debugger-src` is gone (it never had an effect).
503511
- **From 3.x:** version 4 moved from PDF.js 5 to PDF.js 6. If you set `worker-src`, point it at `pdfjs-dist@{{ pdfjsViewer.pdfjsVersion }}`. From 3.0.x, also replace `viewer-extra-styles` and `viewer-extra-styles-urls` with [`injectViewerStyles()`](#injectviewerstyles-css).

0 commit comments

Comments
 (0)