This option is removed now, since:
- It was originally added for the Boot to Gecko (B2G) project, later renamed to Firefox OS, which was discontinued in 2016.
This option was needed then, since B2G was intended to also run on low-end hardware.
- Outside of one example, which is a left-over from the B2G viewer, this option has been unused in the PDF.js project itself for a decade.
- This option has never been covered by *any* tests.
- The result of setting this option to a non-default value is that some images will not renderer, with only a console warning, which could easily make PDF.js appear "broken" to an end-user.
- Image decoding performance, in particular for large and/or complex images, has been significantly improved compared to a decade ago.
- If such an option was requested today, it seems unlikely that we'd actually consider adding it.
This option is removed now, since:
- It was originally added for the Boot to Gecko (B2G) project, later renamed to Firefox OS, which was discontinued in 2016.
The option was needed then, since B2G was intended to also run on low-end hardware.
- Outside of one example, which is a left-over from the B2G viewer, CSS-only zooming has not been used in the PDF.js project itself for a decade.
(However, there are a couple of integration-tests for it though.)
- CSS-only zooming often renders the document "useless" at higher zoom-levels, because of the blurriness.
- Given the current implementation of CSS-only zooming it can break if the initial scale is very large, or if a page has huge dimensions, since the rendering is done without enforcing any limits.
- Removing the option allows us to simplify the code a little bit.
*Note:* A much better user-experience can be had nowadays by setting the `maxCanvasPixels`, `maxCanvasDim`, and/or `capCanvasAreaFactor` options to fairly low values, and then via the `enableDetailCanvas` option (which is `true` by default) re-render only the currently visible viewport at high-resolution.
Currently the `PDFPageView` code, and even the CSS rules, contains a number of special-cases necessary to ensure that it works correctly when used without a surrounding viewer.
That goes back many years, and it was done since the `PDFViewer` could originally only show all pages (in a scrollable view) rather than just one page. However, since five years ago, the `PDFViewer` class also has a `PAGE` scroll-mode allowing only a single page to be shown and even before that the `PDFSinglePageViewer` class existed which allowed only one page to be displayed.
Note that using the `PDFPageView` class directly always had a number of downsides, since a lot of the PDF.js viewer-functionality assumes that a "full" viewer is available; for example it doesn't support searching, links, or adding/modifying annotations.
Furthermore, the Firefox PDF Viewer or the GENERIC PDF.js viewer doesn't need the standalone `PDFPageView` functionality which means that it does nothing except increasing the maintenance burden of the code.
Hence this patch removes all JavaScript and CSS code that only existed to support using `PDFPageView` standalone, and thus also removes the `pageviewer` viewer-component example.
However, the `PDFPageView` class is still being exported in the viewer-components to allow building a fully *custom* viewer.
*Note:* Users previously depending directly on `PDFPageView` are advised to switch to using the `PDFSinglePageViewer` class instead.
This is removed now, since:
- There's most likely very few users of it, since we've only ever seen a handful of questions/issues regarding it over the eight years it has existed.
Few issues could obviously mean that everything just works, but that explanation seems quite unlikely given the experience from the PDF.js project as a whole.
- The JBig2 and JPEG 2000 image decoders are unlikely to still work, ever since the old JavaScript decoders were replaced with WebAssembly ones.
However, there has been no discussions/issues opened about this.
- The Wasm decoders are built specifically for the PDF.js use-case, and the kind of images contained in PDFs, and may not be well suited for general JBig2 and JPEG 2000 images.
- The PDF.js JPEG decoder is still implemented in JavaScript, however in browsers it can largely be replaced by the native `ImageDecoder` API.
In Node.js environments that functionality could be polyfilled e.g. with the `@napi-rs/webcodecs` NPM package.
- This way we slightly simplify the PDF.js image handling code and the build-system.
- If such a build-target was proposed today, I cannot see that we'd actually consider adding it.
*Note:* Any users of the standalone `image_decoders` build can most likely just stay on an older (and working) version.
Replace bundled font programs with glyph data. Generate replacement fonts
with PDF widths and substitutes for missing XFA fonts. Use a JavaScript
fallback when WASM is disabled or fails to load.
Move the listener from the `PDFScriptingManagerComponents` constructor and into the `PDFScriptingManager.prototype.setDocument` method, such that it's possible to easily remove it when closing the document.
- Fix metadata logging, since it's accidentally broken by PR 19778 (over a year ago).
- Modernize, and simplify, the example by using `await` to remove the promise chains.
Note that the `prettier` update introduces a handful of formatting
changes (see https://prettier.io/blog/2026/06/27/3.9.0).
Moreover, the `tsc-alias` update requires explicitly defining the root
URL in the compiler options now, otherwise it errors with `tsc-alias
error: compilerOptions.rootDir is required with implicit baseUrl` (see
https://github.com/justkey007/tsc-alias/pull/259/changes).
This is a left-over from very old code[1], before there were a lot of `getDocument` options and when most of the library configuration was done via the (since removed) `PDFJS` global.
Given all the functionality added through the years, which require configuration[2], in practice it's now unlikely that calling `getDocument` without additional options will work except for the most trivial PDFs.
---
[1] If the `getDocument` function was added today, there's no chance that it'd support anything other than a parameter object.
[2] Note things such as CMaps, standard fonts, wasm-based image decoders, and ICC-based colour spaces.
The percentage calculation is currently "spread out" across various viewer functionality, which we can avoid by having the API handle that instead.
Also, remove the `this.#lastProgress` special-case[1] and just register a "normal" `fullReader.onProgress` callback unconditionally. Once `headersReady` is resolved the callback can simply be removed when not needed, since the "worst" thing that could theoretically happen is that the loadingBar (in the viewer) updates sooner this way. In practice though, since `fullReader.read` cannot return data until `headersReady` is resolved, this change is not actually observable in the API.
---
[1] This was added in PR 8617, close to a decade ago, but it's not obvious to me that it was ever necessary to implement it that way.
The linter found some issues in viewer.html with </input> which isn't required
and a missing closing div in test/resources/reftest-analyzer.html.
The HTML can now be nicely formatted. In order to not break the build for
mozilla-central, the preprocessor has been fixed in order to take into account
the white spaces at the beginning of a comment line.
And finally, make .prettierrc (which is supposed to be either json or yaml)
itself lintable.
These old exceptions have a fair amount of overlap given how/where they are being used, which is likely because they were introduced at different points in time, hence we can shorten and simplify the code by replacing them with a more general `ResponseException` instead.
Besides an error message, the new `ResponseException` instances also include:
- A numeric `status` field containing the server response status, similar to the old `UnexpectedResponseException`.
- A boolean `missing` field, to allow easily detecting the situations where `MissingPDFException` was previously thrown.
Flat config is the new config system used by ESLint 9.
To make the migration easier, they also added
flat config support to ESLint 8.
This commit migrates the various ESLint configs in the repository to use
the new system, **without** upgrading to ESLint 9 yet.
The `@napi-rs/canvas` package has fewer dependencies, which should *hopefully* make installing and using it easier for `pdfjs-dist` end-users. (Over the years we've seen, repeatedly, that `canvas` can be difficult to install successfully.)
Furthermore, this package includes more functionality (such as `Path2D`) which reduces the overall number of dependencies in the PDF.js project.
One point to note is that `@napi-rs/canvas` is a fair bit newer than `canvas`, and has a lot fewer users, however looking at the commit history it does seem to be actively maintained.
Note that I've successfully tested the [Node.js examples](https://github.com/mozilla/pdf.js/tree/master/examples/node), in particular the `pdf2png` one, with this patch applied and things appear to work fine.
Please see:
- https://www.npmjs.com/package/@napi-rs/canvas
- https://github.com/Brooooooklyn/canvas
This unifies the various factory-options, since it's consistent with `CMapReaderFactory`/`StandardFontDataFactory`, and ensures that any needed parameters will always be consistently provided when creating `CanvasFactory`/`FilterFactory`-instances.
As shown in the modified example this may simplify some custom implementations, since we now provide the ability to access the `CanvasFactory`-instance used with a particular `getDocument`-invocation.
The HTML button elements we use are all regular buttons that don't
submit form data to a server. According to
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#notes
those buttons should all have their type set to `button` explicitly, but
we only do that a handful of them. This commit fixes the issue by
consistently giving all our buttons the `button` type.
Co-authored-by: Calixte Denizet <calixte.denizet@gmail.com>
- Ensure that localization works in the GENERIC viewer, even if the necessary locale files cannot be loaded.
This was the behaviour prior to the introduction of Fluent, and it seems worthwhile to keep that (especially since we already bundle the en-US strings anyway).
- Let the `GenericL10n`-implementation use the *bundled* en-US strings directly when no language is provided.
- Remove the `NullL10n`-implementation, and simply fallback to `GenericL10n`, to reduce the maintenance burden of viewer-components localization.
- Indirectly, given the previous point, stop exporting `NullL10n` in the viewer-components since it's now removed.
Note that it was never really intended to be used directly and only existed as a fallback.
*Please note:* This doesn't affect the Firefox PDF Viewer, thanks to the use of import maps.
*Please note:* While following the steps in the README still works with this patch, in the sense that the example runs and successfully renders a PDF document, I unfortunately cannot tell if it illustrates Webpack best practices.
- Remove the `errorWrapper`-element, since it simplifies the example and is consistent with the default viewer; see PR 15533.
- Simplify the l10n-handling, since the `NullL10n` should be able to translate everything e.g. without fallback values; see PR 17146.
- For the generic viewer we use @fluent/dom and @fluent/bundle
- For the builtin pdf viewer in Firefox, we set a localization url
and then we rely on document.l10n which is a DOMLocalization object.
Given the amount of work put into removing `require`-calls from the code-base, let's ensure that new ones aren't accidentally added in the future.
Note that we still have a couple of files where `require` is being used, in particular:
- The Node.js examples, however those will be updated to use `import` in PR 17081.
- The Webpack examples, and related support files, however I unfortunately don't know enough about Webpack to be able to update those. (Hopefully users of that code will help out here, once version `4` is released.)
- The `statcmp`-tool, since *some* of those `require`-calls cannot be converted to `import` without other code changes (and that file is only used during benchmarking).
Please find additional details at https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-commonjs.md
This has been deprecated since version `2.15.349`, which is a year ago.
Removing this will also simplify some upcoming changes, specifically outputting of JavaScript modules in the builds.
Given that the `useOnlyCssZoom` option is essentially just a special-case of the `maxCanvasPixels` functionality, we can combine the two options in order to simplify the overall implementation.
Note that the `useOnlyCssZoom` functionality was only ever used, by default, in the PDF Viewer for the B2G/FirefoxOS project (which was abandoned years ago).
Rather than repeatedly initializing a `canvasFactory`-instance for every page, move it to the document-level instead.
*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
Given that the `ProgressBar`-constructor was updated, we need to update the "mobile-viewer" example as well; this is yet another thing I missed during review.
This patch proposes removing the `browserify` example for the following reasons:
- The last `browserify` release was almost two years ago, according to both https://github.com/browserify/browserify/releases and https://www.npmjs.com/package/browserify?activeTab=versions
- The project no longer seems to be actively maintained, since so far this year there's only been *a single* (seemingly trivial) patch merged; see https://github.com/browserify/browserify/commits/master
- Because of the previous points `browserify` doesn't support modern and up-to-date JavaScript features, as evident from e.g. issue 14731 and multiple issues found in https://github.com/browserify/browserify/issues
- Our `browserify` example is most likely not very commonly used, judging by the very low volume of issues/PRs related to it. Looking at the `git` history of that example the only changes have been lint- or maintenance-related.[1]
- Providing an example for a framework that's no longer actively maintained doesn't seem like a good idea in general, since we probably don't want to steer users towards using (possibly) older frameworks.
- Given that we've never used `browserify` in the PDF.js project, it's also quite difficult to provide support for the example.
---
[1] It's interesting to compare with the `webpack` example, since that's generated both issues *and* also PRs (for missing features) from users.
- Simplify how we look-up the DOM-element, which should also be a tiny bit more efficent.
- Use private class-fields, rather than property-names prefixed with underscores.
- Inline the `#updateBar` helper-method directly in the `percent`-setter, since having a separate method doesn't seem necessary in this case.
- Set the `indeterminate`-class on the ProgressBar DOM-element, to simplify the code.
Finally, also (slightly) re-factors the `PDFViewerApplication.progress`-method to make it a bit smaller.
The original `ProgressBar`-functionality is very old, and could thus do with some general clean-up.
In particular, while it currently accepts various options those have never really been used in either the default viewer or in any examples. The sort of "styling" that these options provided are *much better*, not to mention simpler, done directly with CSS rules.
As part of these changes, the "progress" is now updated using CSS variables rather than by directly modifying the `style` of DOM elements. This should hopefully simplify future changes to this code, see e.g. PR 14898.
Finally, this also fixes a couple of other small things in the "mobile viewer" example.
Given that Node.js doesn't support Workers, general PDF.js performance will be worse when compared to browsers. In an attempt to improve at least memory usage a little bit, update the Node.js examples to release page resources once parsing is done for that page.