5087 Commits

Author SHA1 Message Date
Tim van der Meij
941e17296e
Merge pull request #21313 from Snuffleupagus/Annotation-OC
Add support for Optional Content in the AnnotationLayer (issue 20433)
2026-05-24 15:02:06 +02:00
Jonas Jenwald
bd14524536 Shorten the XfaLayerBuilder.prototype.render method
Given that the "print" intent is handled separately, there's currently a little bit of unnecessary code duplication in this method.
2026-05-23 16:33:23 +02:00
Jonas Jenwald
fb9758303b Add support for Optional Content in the AnnotationLayer (issue 20433) 2026-05-23 12:33:56 +02:00
Tim van der Meij
52d574c539
Merge pull request #21306 from calixteman/dnd_pdf_merging
Allow merging a PDF by dropping it onto the thumbnail viewer
2026-05-21 21:01:42 +02:00
Tim van der Meij
9b5cd3db64
Merge pull request #21304 from Snuffleupagus/PdfTextExtractor-tests
Add basic integration-tests for the `PdfTextExtractor` class
2026-05-21 20:27:53 +02:00
Calixte Denizet
d79043b3af Allow merging a PDF by dropping it onto the thumbnail viewer
Drop an external PDF anywhere in the views-manager thumbnail
sidebar to merge it at the cursor, rather than always inserting
after the current page via the "Add file" button.

The drop reuses the blue separator from page-move drag so the
user can see exactly where the inserted pages will land, and the
merge path is shared with the existing picker so post-merge
selection/current-page behavior stays consistent.
2026-05-20 18:06:55 +02:00
Jonas Jenwald
429b469ecb Add basic integration-tests for the PdfTextExtractor class 2026-05-20 17:26:50 +02:00
Titus Wormer
957e004e38
Make text selection more visible (bug 1879559)
References <https://bugzilla.mozilla.org/show_bug.cgi?id=1879559>
(“In HCM, the text selection is barely visible”).

Continues work from @calixteman who had a partial patch.

This PR improves viewer text-selection highlighting by rendering
selection shapes in the draw layer.

* add selection overlay rendering in the draw layer
  * significant code relates to selections spanning multiple text
    layers/pages, and edges/end-of-content boundaries
* clear selection on rotate/scale/scroll/spread changes

My main question is: how should it appear?
I don’t have access to the Figma file linked on bugzilla.

In the CSS (`draw_layer-builder.css`) there are 3 blocks:

* default
* `@supports` for browsers supporting `backdrop-filter`
* `forced-colors` mode

So it’s possible to design for those (or more).
Personally, the `backdrop-filter: invert(1)` is the most contrast,
so perhaps it’s better to use something else as the default,
and to use `invert(1)` if high contrast mode is used (maybe with a
`prefers-contrast` media query instead)?
2026-05-19 21:10:12 +02:00
Tim van der Meij
00af75905f
Merge pull request #21295 from Snuffleupagus/PDFDocumentProperties-more-tests
Add more integration-tests, with multi-page documents, for the `PDFDocumentProperties` dialog
2026-05-18 20:24:41 +02:00
calixteman
abb8e31408
Merge pull request #21261 from calixteman/bug1960363
Add a Content-Security-Policy to pdf.js' viewer.html (bug 1960363)
2026-05-18 18:24:38 +02:00
Jonas Jenwald
1e62f01773 Improve handling of corrupt pages in the PDFDocumentProperties dialog
If the active page is corrupt that currently results in the entire dialog being "blank", thus providing no information, which seems unfortunate and it's easy enough to only skip `pageSizeField` in that rare case.
2026-05-18 17:38:43 +02:00
Jonas Jenwald
e05b6d6f59 Add more integration-tests, with multi-page documents, for the PDFDocumentProperties dialog
Improve test coverage for multi-page documents, to ensure that:
 - Unnecessary re-parsing is avoided where possible.
 - Rotation, in the viewer, is handled correctly.
 - Different page sizes are handled correctly.
2026-05-18 14:24:05 +02:00
Jonas Jenwald
e8f07d7ca3 [api-minor] Move the getXfaPageViewport helper into the XfaLayer class
This small helper function only exists to support printing of XFA documents, in the viewer, hence it seems like a good idea to (ever so slightly) reduce the official API surface a little bit.
2026-05-16 12:31:53 +02:00
Jonas Jenwald
eda97fe8fc Move the PageViewport class into its own file
This is necessary to prevent import cycles with the next patch.

It also shouldn't hurt to reduce the size of `src/display/display_utils.js` a little bit, since utility-files have a tendency to increase in size over time.
2026-05-16 12:31:40 +02:00
Roland Arnold
16d82e094f fix: inline styles for hidden helper elements
Set layout-neutral styles at the creation sites for the hidden TextLayer
canvas and PDFViewer copy element rather than relying on the shared
web/pdf_viewer.css rule.

This keeps the helper elements invisible and out of layout when viewer CSS
selectors are scoped or omitted, and removes the obsolete hiddenCanvasElement
class and shared CSS rule.
2026-05-14 14:28:41 +01:00
Calixte Denizet
94de952b65
Add a Content-Security-Policy to pdf.js' viewer.html (bug 1960363) 2026-05-14 12:50:07 +02:00
Jonas Jenwald
1079535a1e
Merge pull request #21249 from Snuffleupagus/open-filename-unconditional
Support providing a `filename` unconditionally, when passing binary data to `PDFViewerApplication.open`
2026-05-10 15:48:43 +02:00
Jonas Jenwald
0763c69b6a Support providing a filename unconditionally, when passing binary data to PDFViewerApplication.open
Previously this was only supported in Firefox, however when merging PDFs the `PDFViewerApplication.onSaveAndLoad` method will provide a `filename` unconditionally.
2026-05-10 13:51:33 +02:00
Jonas Jenwald
43ce1bb491 [api-major] Remove the PDFDocumentProxy.prototype.destroy method
This is a left-over from very old code, which pre-dates the introduction of the `PDFDocumentLoadingTask` and it's nothing more than an alias for its `destroy` method.
Given that `PDFDocumentProxy` already provides a way to access the underlying `PDFDocumentLoadingTask` instance, it shouldn't be necessary to have an alias for one of its methods.

*Please note:* For any existing code relying on the removed method, updating it should be as simple as replacing `pdfDocument.destroy()` with `pdfDocument.loadingTask.destroy()`.

---

[1] If the `PDFDocumentProxy` class was added today, there's no chance that it'd include a `destroy` method.
2026-05-09 13:20:39 +02:00
Calixte Denizet
a6cb30a9e5
Make sure the focus moves on the first page of the added pdf after a merge (bug 2034827) 2026-05-06 13:42:49 +02:00
Calixte Denizet
82f55e7dd9
Clear the text layer container when cancelling rendering
It fixes #21217.
2026-05-04 14:36:12 +02:00
Tim van der Meij
038ca33f8e
Optimize runtime of the find controller unit tests
The find controller tests consistently show up in the list of slowest
tests reported by Jasmine. Profiling shows that most of the time is
spent waiting for the find results to arrive, even though the find
command itself is quite fast.

It turns out that the slowdown occurs between receiving the `find` event
and actually triggering the search. The find controller has a hardcoded
delay of 250 milliseconds built in, which was introduced for viewer
performance many years ago because otherwise every keystroke would
trigger a search even though the user's query was not complete yet.

For the unit tests we don't need this delay because, contrary to the
viewer use case, we don't have to account for user interaction and
instead dispatch complete `find` events on the event bus ourselves.
However, since the unit tests were introduced well over a year after
the delay was introduced, due to an oversight it was never made
configurable so we could skip it for the unit tests.

This commit fixes the issue, which locally results in the runtime of
`npx gulp unittest --noChrome` dropping from 39.991 seconds before this
patch to 29.116 seconds afterwards, which is a 27% speedup.
2026-05-01 19:31:13 +02:00
calixteman
7ebf3a4d7c
Merge pull request #21196 from calixteman/bug2035530
Fix free highlight on pages without images (bug 2035530)
2026-04-30 19:34:02 +02:00
Jonas Jenwald
aa08b02a5b Avoid setting page-content for a previous document in the PDFFindController.prototype.#extractText method
Given that all of the relevant API methods are asynchronous it's possible, although quite unlikely, that the existing "is the document active" check won't catch all situations where the document was closed in the middle of searching.
2026-04-29 22:39:53 +02:00
Jonas Jenwald
a6e2a42df1 Improve error handling in the PDFFindController.prototype.#extractText method
This handles *all* errors correctly, if e.g. the document is closed in the middle of searching.
Also, replacing the "promise chains" with more `await` helps simplify the code a little bit.
2026-04-29 22:39:51 +02:00
Calixte Denizet
e7ec356be0
Fix free highlight on pages without images (bug 2035530) 2026-04-29 19:24:35 +02:00
Calixte Denizet
ecd154160d
Fix HCM colors for the views-manager massive unselect button (bug 2035551) 2026-04-28 19:52:53 +02:00
Jonas Jenwald
fae980a72d A couple of internal-viewer fixes
- Bundle the `web/text_layer_builder.css` file correctly, to ensure that textLayer debugging works when the code is *built*.
   Note how loading https://mozilla.github.io/pdf.js/internal-viewer/web/debugger.html currently logs the following error: `GET https://mozilla.github.io/pdf.js/internal-viewer/text_layer_builder.css [HTTP/2 404  7ms]`.

 - Import the `MathClamp` helper function from the *built* library, rather than "manually", since that's more correct.
2026-04-26 19:10:05 +02:00
Jonas Jenwald
9b238b9719 Move the hexNumbers Array into Util, to enable using it in the viewer
This reduces some code duplication, and the new `Util.hexNums` property is now computed lazily.
2026-04-26 12:05:12 +02:00
Jonas Jenwald
1591ddfa8d
Merge pull request #21157 from Snuffleupagus/eslint-radix
Enable the `radix` ESLint rule
2026-04-25 22:27:21 +02:00
Jonas Jenwald
e6dba6ee34 Enable the radix ESLint rule
Many `parseInt` call-sites already provide the `radix` argument, and this rule helps improve consistency in the code-base; see https://eslint.org/docs/latest/rules/radix

*Please note:* The rule is disabled in `src/scripting_api/util.js` for now, since it's not obvious at a glance (at least to me) what the correct `radix` argument should be there.
2026-04-25 12:13:12 +02:00
calixteman
30d060c77a
Merge pull request #21151 from calixteman/bug2034568
Fix clicking on a thumbnail image not navigating to the correct page when using a screen reader (bug 2034568)
2026-04-25 08:20:25 +02:00
Tim van der Meij
7dc4812643
Merge pull request #21138 from calixteman/bug2034111
Fix status label mismatch after merging with a pre-existing selection (bug 2034111)
2026-04-24 20:07:50 +02:00
calixteman
2d896faa1e
Merge pull request #21142 from calixteman/input_color_alpha
[Ink] Replace the opacity slider with an alpha-enabled color input
2026-04-24 15:46:46 +02:00
Calixte Denizet
39eb691252
Fix status label mismatch after merging with a pre-existing selection (bug 2034111) 2026-04-24 14:13:53 +02:00
calixteman
a6382ac97d
Merge pull request #21145 from calixteman/bug2034461
Prompt the user for saving a merged pdf (bug 2034461)
2026-04-24 14:11:36 +02:00
Calixte Denizet
b669fdfc70
Fix clicking on a thumbnail image not navigating to the correct page when using a screen reader (bug 2034568)
Screen readers like NVDA fire synthetic click events on the <img> child of the button rather than on the
thumbnailImageContainer element itself, so the strict classList.contains check silently failed.
2026-04-24 10:10:59 +02:00
Calixte Denizet
987edbb646
Switch to a wasm file for the quickjs sandbox 2026-04-23 22:34:48 +02:00
Calixte Denizet
f266c4d8b8
[Ink] Replace the opacity slider with an alpha-enabled color input
The alpha feature is available in Firefox nightly (with the pref `dom.forms.html_color_picker.enabled` set to `true`).
It's available in Safari but not in Chrome.
2026-04-23 21:37:37 +02:00
Calixte Denizet
302bc5f4d9
Prompt the user for saving a merged pdf (bug 2034461) 2026-04-23 18:37:56 +02:00
Calixte Denizet
9bfad05173 [HCM] Set the correct color for the icon in the merge button when focused with the keyboard (bug 2033603) 2026-04-21 19:24:21 +02:00
Calixte Denizet
8ddbeda4a0
Remove user and password from URLs (bug 2025109) 2026-04-20 20:53:24 +02:00
Calixte Denizet
8c9b819b4e
Add the UI for merging PDFs (bug 2028071) 2026-04-13 19:38:56 +02:00
Tim van der Meij
583c9d6b98
Update dependencies to the most recent versions
Note that the `globals` update rendered two ESLint ignore lines obsolete
because the `Sanitizer` global is now registered [1].

[1] 5d84602967
2026-04-12 16:16:21 +02:00
Calixte Denizet
ea15ac31ef Dont revoke blob URLs while printing but do it after
It fixes #19988.

In Firefox, when printing, the document is cloned and use an image cache
which isn't available when there's a service worker.
2026-04-08 14:04:09 +02:00
calixteman
d6afffe8f6
Merge pull request #21059 from calixteman/bug2028193
Make sure the thumbnails positions are recomputed after a structural change but after a reflow has been done (bug 2028193)
2026-04-07 17:02:07 +02:00
Calixte Denizet
1b2e98f3ce
Make sure the thumbnails positions are recomputed after a structural change but after a reflow has been done (bug 2028193) 2026-04-07 15:48:23 +02:00
Jonas Jenwald
8656b4acb3 Fix the l10n-id for the sidebar toggleButton, in the ViewsManager class
Steps to reproduce:
 1. Open http://localhost:8888/web/viewer.html
 2. Open the console, and run: `PDFViewerApplication.close();`
 3. Note the warning: `[fluent] Missing translations in en-us: pdfjs-toggle-views-manager-button`
2026-04-07 11:13:35 +02:00
Jonas Jenwald
5aaf30a071
Merge pull request #21018 from Snuffleupagus/Node-22
[api-minor] Update the minimum supported Node.js version to 22
2026-04-05 12:39:36 +02:00
Jonas Jenwald
f6bac014ea [api-minor] Remove PostScriptCompiler and PostScriptEvaluator, since it's now dead code (PR 21023 follow-up)
These classes, and various related code, became unused after PR 21023 with only unit-tests actually running that code now.

Also removes the `isEvalSupported` API option, since the `PostScriptCompiler` was the only remaining code where `eval` was used.
2026-04-03 22:14:14 +02:00