You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 695dca9
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/_data/pdfjsAttributes.js
+12-11Lines changed: 12 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
// Attributes of <pdfjs-viewer-element>, rendered as the reference tables and the playground.
2
2
// `update`: live = applies immediately, load = applies to the next document load,
3
-
// init = read only when the viewer is built, so set it before the element is connected.
3
+
// init = read only when the viewer is built, so set it before the element is connected,
4
+
// none = has no effect.
4
5
constsamples="/pdfjs-viewer/samples/";
5
6
6
7
exportdefault[
@@ -75,9 +76,9 @@ export default [
75
76
{
76
77
name: "locale-src-template",
77
78
group: "interface",
78
-
description: "URL of the locale file, with a `{locale}` placeholder. Use it to self-host locales.",
79
+
description: "Absolute URL of the locale file, with a `{locale}` placeholder. Use it to self-host locales. Read when the viewer is built and when `locale` changes.",
description: "Folder of CMaps, needed for some CJK text.",
135
+
description: "Absolute URL of the CMaps folder, ending in `/`. Needed for some CJK text.",
135
136
default: "`../web/cmaps/`",
136
137
update: "load",
137
138
},
138
139
{
139
140
name: "standard-font-data-url",
140
141
group: "resources",
141
-
description: "Folder of the standard fonts, for PDFs that use non-embedded base fonts.",
142
+
description: "Absolute URL of the standard fonts folder, ending in `/`. For PDFs that use non-embedded base fonts.",
142
143
default: "`../web/standard_fonts/`",
143
144
update: "load",
144
145
},
145
146
{
146
147
name: "wasm-url",
147
148
group: "resources",
148
-
description: "Folder of the WASM image decoders (JPEG 2000, JBIG2).",
149
+
description: "Absolute URL of the WASM image decoders folder (JPEG 2000, JBIG2), ending in `/`.",
149
150
default: "`../web/wasm/`",
150
151
update: "load",
151
152
},
152
153
{
153
154
name: "icc-url",
154
155
group: "resources",
155
-
description: "Folder of ICC color profiles.",
156
+
description: "Absolute URL of the ICC color profiles folder, ending in `/`.",
156
157
default: "`../web/iccs/`",
157
158
update: "load",
158
159
},
159
160
{
160
161
name: "image-resources-path",
161
162
group: "resources",
162
-
description: "Folder of annotation icons (`annotation-*.svg`). Shipped in the package as `dist/images/`.",
163
+
description: "Folder of annotation icons (`annotation-*.svg`), shipped in the package as `dist/images/`. The default is relative to your page, so set this or `assets-base`.",
163
164
default: "`./images/`, or `assets-base` + `images/`",
164
-
update: "load",
165
+
update: "init",
165
166
},
166
167
{
167
168
name: "sandbox-bundle-src",
@@ -173,8 +174,8 @@ export default [
173
174
{
174
175
name: "debugger-src",
175
176
group: "resources",
176
-
description: "PDF.js debugger script URL.",
177
+
description: "PDF.js debugger script URL. It has no effect: the debugger isn't shipped in the package, and the element offers no way to turn it on.",
Copy file name to clipboardExpand all lines: src/pdfjs-viewer/index.md
+68-26Lines changed: 68 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: pdfjs-viewer · PDF viewer web component
4
4
description: Docs for @missing-elements/pdfjs-viewer, a self-hostable PDF viewer web component based on the PDF.js default viewer. Install, attributes, API, theming, hosting and framework guides.
5
5
---
6
6
7
-
The full PDF.js viewer as one HTML element. It runs in an isolated iframe and has no runtime dependencies. PDF.js and its worker ship inside the package, so nothing loads from a CDN unless you choose to. Each **Try** button applies its example to the live preview, and **Reset** puts the preview back to its defaults.
7
+
The full PDF.js viewer as one HTML element. It runs in an isolated iframe and has no runtime dependencies. PDF.js and its worker ship inside the package, so by default nothing loads from a CDN. The one exception is locale files, which come from jsDelivr when you set `locale`. Each **Try** button applies its example to the live preview, and **Reset** puts the preview back to its defaults.
The **Updates** column in the tables below says when a change takes effect:
47
47
48
-
-**Live**: immediately. Changing `src` opens the new file without rebuilding the viewer. `page`, `zoom`, `pagemode`, `search` and `phrase` are applied together, so changing any of them also goes to the page in `page`, or to page 1 when `page` is unset.
48
+
-**Live**: immediately. Changing `src` opens the new file without rebuilding the viewer. `page`, `zoom`, `pagemode`, `search` and `phrase` are applied together. Changing any of them also goes to the page in `page` (page 1 when it's unset) and resets the sidebar to `pagemode`, closing a sidebar the reader opened.
49
49
-**Next load**: with the next document the viewer opens.
50
50
-**Before connect**: read once, when the viewer is built. Set it before you add the element to the page.
51
51
@@ -78,7 +78,7 @@ You rarely need these. See [Hosting](#hosting).
78
78
79
79
### PDF.js resources
80
80
81
-
Data that only some PDFs need. The package doesn't include it, so see[PDF.js resources](#cmaps-fonts-and-other-resources) before you set these.
81
+
Data that only some PDFs need. The package doesn't include it, and the defaults are relative paths that don't work inside the viewer. See[PDF.js resources](#cmaps-fonts-and-other-resources) before you set these.
The options are applied while the viewer is being built, so call this right after you add the element. A call made after `initPromise` has resolved has no effect until the viewer rebuilds. Each call replaces the options of the previous one. It resolves to `{ viewerOptions }` once the viewer is ready.
112
+
The options are applied while the viewer is being built, so call this right after you add the element. A call made after `initPromise` has resolved has no effect until the viewer rebuilds. Each call replaces the options of the previous one, and the options are cleared once applied. A rebuild (a `locale` change that can't be applied in place, or moving the element to another place in the page) drops them, so call it again after one. It resolves to `{ viewerOptions }` once the viewer is ready.
113
113
114
114
### `injectViewerStyles(css)`
115
115
@@ -150,7 +150,7 @@ The default Paper & Ink theme follows the system color scheme. To force one sche
150
150
151
151
### Your own colors
152
152
153
-
The viewer is styled with CSS custom properties. To restyle it, override them with `injectViewerStyles`. Paper & Ink sets its palettes on `:root`, and on `:root[data-color-scheme]` when a scheme is forced, so target both selectors. Any variable you don't override keeps the current scheme's value, so pair a custom palette with a fixed `viewer-css-theme`:
153
+
The viewer is styled with CSS custom properties. To restyle it, override them with `injectViewerStyles`. Paper & Ink sets its palette on `:root`, and on `:root[data-color-scheme=dark]` when dark is forced, so target both selectors. Any variable you don't override keeps the current scheme's value, so pair a custom palette with a fixed `viewer-css-theme`:
@@ -193,15 +193,15 @@ The interface is in English unless you set `locale`. The locale file is download
193
193
194
194
Right-to-left locales such as `ar` and `he` also switch the layout direction.
195
195
196
-
> **Known issue in v{{ pdfjsViewer.version }}:** codes with a region, such as `pt-BR`, `zh-CN`, `es-ES` and `sv-SE`, don't load and the viewer stays in English. Language-only codes work.
196
+
> **Known issue in v{{ pdfjsViewer.version }}:** codes are checked against a lowercase list, so codes with a region, such as `pt-BR`, `zh-CN`, `es-ES` and `sv-SE`, are ignored and the viewer stays in English. These languages have no language-only code to fall back on. As a workaround, use the lowercase code, such as `pt-br`, with a self-hosted `locale-src-template` that uses the same lowercase folder name.
197
197
198
-
To serve locale files yourself, which is useful under a strict CSP or when you can't rely on third parties, copy them from [mozilla-l10n/firefox-l10n](https://github.com/mozilla-l10n/firefox-l10n) (`<locale>/toolkit/toolkit/pdfviewer/viewer.ftl`) and point `locale-src-template` at them:
198
+
To serve locale files yourself, which is useful under a strict CSP or when you can't rely on third parties, copy them from [mozilla-l10n/firefox-l10n](https://github.com/mozilla-l10n/firefox-l10n) (`<locale>/toolkit/toolkit/pdfviewer/viewer.ftl`) and point `locale-src-template` at them. The template must be an absolute URL: a relative one breaks all of the viewer's interface text.
@@ -211,9 +211,9 @@ The element loads the viewer at runtime from five files next to `pdfjs-viewer-el
211
211
212
212
### Bundlers and `assets-base`
213
213
214
-
**Vite, Rollup and webpack 5** need no configuration. The element references its files as `new URL('./file', import.meta.url)`, so these bundlers emit them as assets and rewrite the URLs.
214
+
**Vite and webpack 5** need no configuration. The element references its files as `new URL('./file', import.meta.url)`, so these bundlers emit them as assets and rewrite the URLs.
215
215
216
-
**esbuildand other bundlers** that don't understand that pattern move the element into your bundle without the files, and the viewer fails with 404s. Serve the package's `dist` folder as static files and point `assets-base` at it:
216
+
**esbuild, plain Rollup and other bundlers** that don't handle that pattern move the element into your bundle without the files, and the viewer fails with 404s. Serve the package's `dist` folder as static files and point `assets-base` at it:
@@ -231,6 +231,8 @@ The same attribute can load the files from a CDN:
231
231
232
232
`assets-base` is read when the viewer is built, so set it before the element is connected. A per-file attribute such as `worker-src` overrides it for that file.
233
233
234
+
Annotation icons need this whichever bundler you use. PDF.js loads them by name at runtime (`annotation-<name>.svg`), so no bundler emits them, and the default path is relative to your page. Serve the package's `dist/images` folder and point `image-resources-path` at it, or set `assets-base`, which covers the icons too.
235
+
234
236
### Static pipelines with hashed file names
235
237
236
238
If your pipeline renames files, for example with content hashes, set each runtime file URL instead of `assets-base`:
@@ -247,11 +249,13 @@ If your pipeline renames files, for example with content hashes, set each runtim
247
249
</pdfjs-viewer-element>
248
250
```
249
251
250
-
Annotation icons are loaded by name (`annotation-<name>.svg`), so keep the `dist/images` folder unhashed and point `image-resources-path` at it.
252
+
Keep the `dist/images` folder unhashed: annotation icons are loaded by name.
251
253
252
254
### Worker
253
255
254
-
By default the worker is the bundled `pdf.worker.min.mjs`, served from your own origin. That works under a strict `script-src 'self'` policy. Set `worker-src` only to serve it from somewhere else, and use the matching PDF.js version ({{ pdfjsViewer.pdfjsVersion }}). A mismatch stops the viewer with an "API version does not match Worker version" error.
256
+
By default the worker is the bundled `pdf.worker.min.mjs`, served from your own origin. PDF.js starts it from a `blob:` URL, so if your page has a Content Security Policy, allow `worker-src 'self' blob:`. Without that, PDF.js falls back to running on the main thread, which works but is slower.
257
+
258
+
Set `worker-src` only to serve the worker from somewhere else, and use the matching PDF.js version ({{ pdfjsViewer.pdfjsVersion }}). A mismatch stops the viewer with the error `The API version "…" does not match the Worker version "…"`.
255
259
256
260
```html
257
261
<pdfjs-viewer-element
@@ -262,18 +266,18 @@ By default the worker is the bundled `pdf.worker.min.mjs`, served from your own
262
266
263
267
### CMaps, fonts and other resources
264
268
265
-
Most PDFs render with just the package. Some need extra PDF.js data: CMaps for some CJK text, standard fonts for non-embedded base fonts, WASM decoders for JPEG 2000 and JBIG2 images, and the scripting sandbox for PDFs with JavaScript. The package doesn't include these, and the defaults point at paths that usually don't exist on your site.
269
+
Most PDFs render with just the package. Some need extra PDF.js data: CMaps for some CJK text, standard fonts for non-embedded base fonts, WASM decoders for JPEG 2000 and JBIG2 images, and the scripting sandbox for PDFs with JavaScript. The package doesn't include these, and the defaults are relative paths that don't work inside the viewer.
266
270
267
-
If your documents need them, copy the folders from `pdfjs-dist@{{ pdfjsViewer.pdfjsVersion }}` into your static files and point the attributes at them:
271
+
If your documents need them, copy the folders from `pdfjs-dist@{{ pdfjsViewer.pdfjsVersion }}` into your static files and point the attributes at them. Use absolute URLs that end in `/`. PDF.js fetches these folders from its worker, which runs from a `blob:` URL where relative paths don't resolve, and it rejects a folder URL without the trailing slash.
-**From 3.x:** remove `use-built-in-worker`. The bundled worker is now always the default, and `worker-src` overrides it.
430
-
-**From 2.x:** PDF.js is now bundled, so remove `viewer-path` and your copy of the PDF.js prebuild. Replace `initialize()` with [`initPromise`](#initpromise), and `viewer-extra-styles` / `viewer-extra-styles-urls` with [`injectViewerStyles()`](#injectviewerstyles-css). The `nameddest`, `text-layer`, `disable-*` and `verbosity` attributes are gone. Their PDF.js equivalents (`disableRange`, `textLayerMode` and so on) can be set with [`setViewerOptions()`](#setvieweroptions-options).
468
+
-**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).
469
+
-**From 2.x:** PDF.js is now bundled, so remove `viewer-path` and your copy of the PDF.js prebuild. Replace `initialize()` with [`initPromise`](#initpromise), and `viewer-extra-styles` and `viewer-extra-styles-urls` with [`injectViewerStyles()`](#injectviewerstyles-css). The `nameddest`, `text-layer`, `disable-*` and `verbosity` attributes are gone:
470
+
-`disableRange`, `disableStream`, `disableAutoFetch`, `disableFontFace`, `textLayerMode` and `verbosity` can be set as PDF.js options with [`setViewerOptions()`](#setvieweroptions-options).
471
+
- For a named destination, call `viewerApp.pdfLinkService.goToDestination(name)` after [`initPromise`](#initpromise) resolves.
0 commit comments