From 15af8b8436405e1257ab718b078406d9866af042 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Sat, 7 Nov 2026 17:36:52 +0200 Subject: [PATCH 1/2] Bump pdfjs-viewer to 4.5.0 Co-Authored-By: Claude Opus 5.5 --- package.json | 2 +- pnpm-lock.yaml | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 155b0ec..62b8249 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,6 @@ "@11ty/eleventy-plugin-syntaxhighlight": "5.0.2" }, "dependencies": { - "@missing-elements/pdfjs-viewer": "4.4.2" + "@missing-elements/pdfjs-viewer": "4.5.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e1a5ea6..aaa287f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@missing-elements/pdfjs-viewer': - specifier: 4.4.2 - version: 4.4.2 + specifier: 4.5.0 + version: 4.5.0 devDependencies: '@11ty/eleventy': specifier: 3.1.7 @@ -77,8 +77,8 @@ packages: resolution: {integrity: sha512-oI7m8pa7/IAU/3lqRU9vjBbs20iKFo7x+1K9kT3aVira6scc1X9MjBdgLCHzLJeJ7iB6wydioA+kr9/qPnvmlQ==} engines: {node: '>=18'} - '@missing-elements/pdfjs-viewer@4.4.2': - resolution: {integrity: sha512-Lq651Ukf2Evac4efj3JR/6u1atxbDqiklQGgQfL9bJeaEm5IMnw+vd15qCD7WyZOqsqcI/jZpdYFOnkv5h2rsw==} + '@missing-elements/pdfjs-viewer@4.5.0': + resolution: {integrity: sha512-BxwuHJxt0PYGNYweqQzV5XBHxdFmZRrmyrnDyQUmNvUPsdAMja+Ms86Kxz+9ruWrntw1Zg/gX5kr2o/en6wo4Q==} '@napi-rs/canvas-android-arm64@1.0.13': resolution: {integrity: sha512-trn7AaDzQ+yeeA0ezhkC7cB1ZDPtp4UYk0EvB5F8qtYL9jEVWtVrU30WOpI52DszoTxaTsCgf5PP4ZVaOlOIHQ==} @@ -438,8 +438,8 @@ packages: resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==} engines: {node: '>= 0.8'} - pdfjs-dist@6.4.299: - resolution: {integrity: sha512-AVl138zALtfaAPvADulE0PZThbYzCBS79nL4pOSL/6Sm/4AH5A21BD9VHt97OlCuzJuCpmeZtAtkinisF4Vb1g==} + pdfjs-dist@6.5.438: + resolution: {integrity: sha512-vg8Pw1x+AFKy4AMDvhuWl5cOYV8d698UoEANoFFhc79hqXDnZQqnOXoxw3HG907WHOg1JYOvLhP756boddFxpA==} engines: {node: '>=22.13.0 || >=24'} picomatch@4.0.7: @@ -678,9 +678,9 @@ snapshots: minimatch: 3.1.5 slash: 3.0.0 - '@missing-elements/pdfjs-viewer@4.4.2': + '@missing-elements/pdfjs-viewer@4.5.0': dependencies: - pdfjs-dist: 6.4.299 + pdfjs-dist: 6.5.438 '@napi-rs/canvas-android-arm64@1.0.13': optional: true @@ -970,7 +970,7 @@ snapshots: parseurl@1.3.3: {} - pdfjs-dist@6.4.299: + pdfjs-dist@6.5.438: optionalDependencies: '@napi-rs/canvas': 1.0.13 From 8d0b8b7ac46e9c1280ad2afdcc5a741356ab1b55 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Sat, 7 Nov 2026 17:36:52 +0200 Subject: [PATCH 2/2] Document renderer-src and worker rendering Add renderer-src to the attribute table and the TypeScript attribute list. The Worker section explains how to turn on PDF.js 6.5's worker rendering, the CSP it needs and its fallback. Hashed pipelines need renderer-src too. The migration note for 4.5 says a pinned worker-src must move to PDF.js 6.5, and that TypeScript now rejects a bare Uint8Array in viewerApp.open(). Co-Authored-By: Claude Opus 5.5 --- src/_data/pdfjsAttributes.js | 9 ++++++++- src/pdfjs-viewer/index.md | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/_data/pdfjsAttributes.js b/src/_data/pdfjsAttributes.js index ee5a083..39dc205 100644 --- a/src/_data/pdfjsAttributes.js +++ b/src/_data/pdfjsAttributes.js @@ -89,7 +89,7 @@ export default [ { name: "assets-base", group: "files", - 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).", + 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).", default: "Folder of `pdfjs-viewer-element.js`", update: "init", }, @@ -100,6 +100,13 @@ export default [ default: "Bundled `pdf.worker.min.mjs`", update: "load", }, + { + name: "renderer-src", + group: "files", + description: "PDF.js renderer worker module URL, used only when [worker rendering](#worker) is on. Must match the bundled PDF.js version.", + default: "Bundled `pdf.renderer.min.mjs`", + update: "load", + }, { name: "pdfjs-lib-src", group: "files", diff --git a/src/pdfjs-viewer/index.md b/src/pdfjs-viewer/index.md index 5f19a01..5169be9 100644 --- a/src/pdfjs-viewer/index.md +++ b/src/pdfjs-viewer/index.md @@ -209,7 +209,7 @@ If your page has a Content Security Policy, allow the locale file's origin in `c ## Hosting -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. +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. ### Bundlers and `assets-base` @@ -276,6 +276,8 @@ If your pipeline renames files, for example with content hashes, set each runtim ``` +If you turn on [worker rendering](#worker), set `renderer-src` too. + 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. ### Worker @@ -291,6 +293,10 @@ Set `worker-src` only to serve the worker from somewhere else, and use the match ``` +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. + +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. + ### CMaps, fonts and other resources 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' type PdfjsViewerAttribute = | 'src' | 'page' | 'zoom' | 'pagemode' | 'search' | 'phrase' | 'viewer-css-theme' | 'locale' | 'locale-src-template' | 'iframe-title' - | 'assets-base' | 'worker-src' | 'pdfjs-lib-src' | 'viewer-src' | 'viewer-css-src' | 'theme-css-src' + | 'assets-base' | 'worker-src' | 'renderer-src' | 'pdfjs-lib-src' + | 'viewer-src' | 'viewer-css-src' | 'theme-css-src' | 'c-map-url' | 'standard-font-data-url' | 'wasm-url' | 'icc-url' | 'image-resources-path' | 'sandbox-bundle-src' @@ -498,6 +505,7 @@ import '@missing-elements/pdfjs-viewer' // was: import 'pdfjs-viewer-element' If you're coming from an older version: +- **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). - **From 4.4.0 or earlier:** if your Content Security Policy allows `blob:` in `connect-src` only for locales, you can remove it. - **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). - **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).