20966 Commits

Author SHA1 Message Date
Jonas Jenwald
92b065c87e Replace a number of semi-private fields with actual private ones in src/core/document.js
These are fields that can be moved out of their class constructors, and be initialized directly.
2025-05-07 13:41:44 +02:00
Jonas Jenwald
39803a9f25 Replace a number of semi-private methods with actual private ones in src/core/document.js
There's a few remaining cases that are used with either cached getters or `BasePdfManager.prototype.ensure`-methods, and those cannot be converted.
2025-05-07 13:41:36 +02:00
Jonas Jenwald
0ded85e9b3 Add a Page helper method to create a PartialEvaluator-instance
Currently we repeat the same identical code five times in the `Page`-class when creating a `PartialEvaluator`-instance, which given the number of parameters it needs seems like unnecessary duplication.
2025-05-07 13:41:29 +02:00
Jonas Jenwald
6f052312d6
Merge pull request #19895 from Snuffleupagus/ObjectLoader-improve
Unify method return values in the `ObjectLoader` class, and simplify how the `ObjectLoader` is used
2025-05-06 21:18:09 +02:00
Jonas Jenwald
384a09113c Run CI tests in Node.js version 24
Node.js version 24 was just released, see https://github.com/nodejs/release#release-schedule, hence we should run tests in that version in order to help catch any possible issues as soon as possible.
Also, since version 23 will reach EOL (end-of-life) in less than a month we stop running tests in that version.
2025-05-06 18:43:02 +02:00
Jonas Jenwald
62009ffa70 Simplify how the ObjectLoader is used
The `ObjectLoader.prototype.load` method has a fast-path, which avoids any lookup/parsing if the entire PDF document is already loaded.
However, we still need to create an `ObjectLoader`-instance which seems unnecessary in that case.

Hence we introduce a *static* `ObjectLoader.load` method, which will help avoid creating `ObjectLoader`-instances needlessly and also (slightly) shortens the call-sites.
To ensure that the new method will be used, we extend the `no-restricted-syntax` ESLint rule to "forbid" direct usage of `new ObjectLoader()`.
2025-05-06 15:49:59 +02:00
Jonas Jenwald
ef1ad675c2 Unify method return values in the ObjectLoader class
Given that all the methods are already asynchronous we can just use `await` more throughout this code, rather than having to explicitly return function-calls and `undefined`.
Note also how none of the `ObjectLoader.prototype.load` call-sites use the return value.
2025-05-06 15:43:00 +02:00
calixteman
04400c588f
Merge pull request #19893 from calixteman/issue19517
Downscale jpeg2000 images, if needed, while decoding them
2025-05-05 22:53:49 +02:00
Calixte Denizet
ac925f4f1b Downscale jpeg2000 images, if needed, while decoding them
It fixes #19517.
2025-05-05 22:39:59 +02:00
Tim van der Meij
06f44916c8
Merge pull request #19889 from Snuffleupagus/loadXfaResources
Slightly re-factor how we pre-load fonts and images in XFA documents
2025-05-04 14:28:11 +02:00
Jonas Jenwald
d9548b1c18 Slightly re-factor how we pre-load fonts and images in XFA documents
Rather than "manually" invoking the methods from the `src/core/worker.js` file we introduce a single `PDFDocument`-method that handles this for us, and make the current methods private.
Since this code is only invoked at most *once* per document, and only for XFA documents, we can use `BasePdfManager.prototype.ensureDoc` directly rather than needing a stand-alone method.
2025-05-04 13:44:33 +02:00
Jonas Jenwald
604153957a Reduce duplication when parsing fonts in loadXfaFonts
Currently we repeat virtually the same code when calling the `PartialEvaluator.prototype.handleSetFont` method, which we can avoid by introducing an inline helper function.
2025-05-04 13:42:17 +02:00
Jonas Jenwald
2979e23f3c Ensure that XFAFactory.prototype.isValid returns a boolean value
Considering the name of the method, and how it's actually being used, you'd expect it to return a boolean value.
Given how it's currently being used this inconsistency doesn't cause any issues, however we should still fix this.
2025-05-04 13:42:17 +02:00
Tim van der Meij
5ca57fbd4b
Merge pull request #19885 from Snuffleupagus/loadXfaImages-simplify
Simplify the `loadXfaImages` method and related code
2025-05-04 13:41:06 +02:00
Tim van der Meij
22cb3080ee
Merge pull request #19887 from Snuffleupagus/serializeXfaData-simplify
Simplify the `serializeXfaData` method and related code
2025-05-04 13:38:01 +02:00
Tim van der Meij
bd81d390c7
Merge pull request #19888 from Snuffleupagus/rm-BasePdfManager-catalog-getter
Remove the `BasePdfManager.prototype.catalog` getter
2025-05-04 13:33:16 +02:00
Jonas Jenwald
b3e16800f5 Remove the BasePdfManager.prototype.catalog getter
This is only invoked *once* and it can be trivially replaced by the `ensureCatalog`-method, since the code where it's used is already asynchronous.
2025-05-03 13:40:23 +02:00
Jonas Jenwald
b531720d9c Simplify the serializeXfaData method and related code
Rather than having a dedicated `BasePdfManager`-method for this one call-site we can instead change `PDFDocument.prototype.serializeXfaData` to a non-async method, that we invoke via `BasePdfManager.prototype.ensureDoc`.
2025-05-03 11:20:42 +02:00
Jonas Jenwald
122822a750 Simplify the loadXfaImages method and related code
Currently we create an intermediate `Dict` during parsing, however that seems unnecessary since (note especially the second point):
 - The `NameOrNumberTree.prototype.getAll` method will already resolve any references, as needed, during parsing.
 - The `Catalog.prototype.xfaImages` getter is invoked, via the `BasePdfManager`-instance, such that any `MissingDataException`s are already handled correctly.
2025-05-02 11:53:41 +02:00
calixteman
91bfe12f38
Merge pull request #19883 from gpanakkal/checkbutton-tostyle
Fix arguments in `toStyle` call in `CheckButton`
2025-05-01 22:08:03 +02:00
Gautam Panakkal
7bba3bd4ad Add missing this arg to toStyle in CheckButton.prototype.[$toHTML] 2025-05-01 10:19:28 -07:00
Jonas Jenwald
fc92e4059a
Merge pull request #19884 from Snuffleupagus/issue-19835-2
Allow to, optionally, keep Unicode escape sequences in  `stringToPDFString` (PR 17331 follow-up)
2025-05-01 11:39:13 +02:00
Jonas Jenwald
b629bafd1c Allow to, optionally, keep Unicode escape sequences in stringToPDFString (PR 17331 follow-up)
Currently *some* of the links[1] on page three of the `issue19835.pdf` test-case aren't clickable, since the destination (of the LinkAnnotation) becomes empty.
The reason is that these destinations include the character `\x1b`, which is interpreted as the start of a Unicode escape sequence specifying the language of the string; please refer to section [7.9.2.2 Text String Type](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G6.1957385) in the PDF specification.

Hence it seems that we need a way to optionally disable that behaviour, to avoid a "badly" formatted string from becoming empty (or truncated), at least for cases where we are:
 - Parsing named destinations[2] and URLs.
 - Handling "strings" that are actually /Name-instances.
 - Building a lookup Object/Map based on some PDF data-structure.

*NOTE:* The issue that prompted this patch is obviously related to destinations, however I've gone through the `src/core/` folder and updated various other `stringToPDFString` call-sites that (directly or indirectly) fit the categories listed above.

---
[1] Try clicking on anything on the line containing "Item 7A. Quantitative and Qualitative Disclosures About Market Risk 27".

[2] Unfortunately just skipping `stringToPDFString` in this case would cause other issues, such as the named destination becoming "unusable" in the viewer; see e.g. issues 14847 and 14864.
2025-04-30 20:51:10 +02:00
Jonas Jenwald
254431df1e Avoid extra lookup/parsing when all destinations are already available
Whenever we cannot find a destination we'll fallback to checking all destinations, to account for e.g. out-of-order NameTrees, and in those cases any subsequent destination-lookups can be made a tiny bit more efficient by immediately checking the already cached destinations.
2025-04-30 15:26:00 +02:00
calixteman
b8de9a372f
Merge pull request #19856 from calixteman/bug1936605
Don't update the visible canvas at 60 fps (bug 1936605)
2025-04-29 22:31:02 +02:00
Jonas Jenwald
0922aa9e9d
Merge pull request #19880 from Snuffleupagus/numberToString-assert-number
Assert that `numberToString` is called with a number (issue 19877)
2025-04-29 20:35:32 +02:00
calixteman
262a1f9895
Merge pull request #19881 from calixteman/bug1963407
Fix the bbox when saving a rotated text field (bug 1963407)
2025-04-29 20:33:53 +02:00
Jonas Jenwald
f5faf86180 Assert that numberToString is called with a number (issue 19877)
*NOTE:* Given that this is an *internal* function, used only in the worker-thread, it's not clear to me that this is an entirely "necessary" change.
2025-04-29 20:31:24 +02:00
Calixte Denizet
7a251b206e Fix the bbox when saving a rotated text field (bug 1963407) 2025-04-29 18:49:07 +02:00
Calixte Denizet
ecc56a61e6 Don't update the visible canvas at 60 fps (bug 1936605)
Instead, we update the visible canvas every 500ms.
With large canvas, updating at 60fps lead to a lot gfx transactions and it can take a lot of time.
For example, with wuppertal_2012.pdf on Windows, displaying it at 150% takes around 14 min !!! without
this patch when it takes only around 14 sec with. Even at 30% it helps to improve the performance
by around 20%.
2025-04-29 18:35:21 +02:00
Jonas Jenwald
c1a398d932
Merge pull request #19876 from Snuffleupagus/Node-polyfill-navigator
Add a basic `navigator` polyfill for older Node.js versions
2025-04-29 10:04:19 +02:00
calixteman
2e10ff6dd4
Merge pull request #19855 from 1Jesper1/hotfix/useractivation-response
Add useractivation check for response function
2025-04-28 13:14:51 +02:00
Jonas Jenwald
3d4e8bb17e Add a basic navigator polyfill for older Node.js versions
Modern Node.js versions now include a `navigator` implementation, with a few basic properties, that's actually enough for the PDF.js use-cases; please see https://nodejs.org/api/globals.html#navigator
Unfortunately we still support Node.js version `20`, hence we add a basic polyfill since that allows simplifying the code slightly.
2025-04-28 13:07:12 +02:00
Tim van der Meij
b47b248e15
Merge pull request #19875 from timvandermeij/bump
Bump the stable version in `pdfjs.config`
2025-04-27 14:53:05 +02:00
Tim van der Meij
6d0e8d752d
Bump the stable version in pdfjs.config 2025-04-27 14:49:27 +02:00
Tim van der Meij
4f7761353c
Merge pull request #19873 from timvandermeij/fix-editor-undo-bar-intermittents
Fix the "must work properly when selecting undo by keyboard" integration test
v5.2.133
2025-04-27 14:15:34 +02:00
Tim van der Meij
967e34046a
Fix the "must work properly when selecting undo by keyboard" integration test
This integration test fails intermittently because the undo button can
only be activated if focus can be put on it, and that in turn can only
happen if it's visible. The test tried to make sure that the undo bar
is visible, but checking for the absence of the `hidden` attribute is
unfortunately not enough to assert visibility according to Puppeteer
documentation [1]. Moreover, the undo button wasn't checked at all.

To fix the issue we let Puppeteer do the visibility detection for the
undo bar by providing the `visible: true` option to `waitForSelector`
[2]. This is consistent with the other tests that already do this, and
also with the existing code that detects if the undo bar is hidden
(which uses the `hidden: true` option of `waitForSelector`). Moreover,
we wait for the undo button to be present before putting focus on it.

For consistency, and to avoid intermittent failures elsewhere, we mirror
this solution to the other undo bar/button tests of the various editors.

[1] https://pptr.dev/api/puppeteer.elementhandle.isvisible
[2] https://pptr.dev/api/puppeteer.waitforselectoroptions
2025-04-27 14:00:50 +02:00
Tim van der Meij
9e1f93e5eb
Merge pull request #19874 from Snuffleupagus/issue-19871
Always render the Annotation- and XFA-layers with light `color-scheme` (issue 19871)
2025-04-27 11:54:08 +02:00
Jonas Jenwald
0852c42c15 Always render the Annotation- and XFA-layers with light color-scheme (issue 19871)
The intention with PR 19819 was to change how colours are specified for the viewer UI, however it wasn't intended to affect elements in the Annotation- and XFA-layers.
Hence we enforce the light `color-scheme` for these layers, and also make sure to provide a default `color` for PopupAnnotations.
2025-04-26 20:44:07 +02:00
Tim van der Meij
48b7d9f424
Merge pull request #19869 from timvandermeij/updates
Update dependencies and translations to the most recent versions
2025-04-26 18:01:22 +02:00
Tim van der Meij
b8dd236ae6
Update translations to the most recent versions 2025-04-26 15:52:12 +02:00
Tim van der Meij
cbf61712f9
Update dependencies to the most recent versions 2025-04-26 15:51:20 +02:00
Tim van der Meij
a40bf37184
Merge pull request #19866 from Snuffleupagus/updateUrlHash
Avoid (most) string parsing when removing/replacing the hash property of a URL
2025-04-26 12:21:38 +02:00
Jonas Jenwald
c2d88540b4
Merge pull request #19868 from Snuffleupagus/MathClamp-4
Use the `MathClamp` helper function more in the `web/` folder (PR 19617 follow-up)
2025-04-26 12:07:30 +02:00
Tim van der Meij
6891602e7f
Merge pull request #19858 from luckymore/master
Tweak the Node.js version listed in "engines", to ensure that process.getBuiltinModule is available
2025-04-26 11:45:27 +02:00
Tim van der Meij
2fc325e4f8
Merge pull request #19814 from loganrosen/beginner-bug-readme
Fix beginner bugs link in README
2025-04-26 11:29:41 +02:00
Jonas Jenwald
af3d13c22d Use the MathClamp helper function more in the web/ folder (PR 19617 follow-up)
There's one more spot that I missed in PR 19617.
2025-04-26 11:09:52 +02:00
Jonas Jenwald
abc9522886 Avoid (most) string parsing when removing/replacing the hash property of a URL 2025-04-25 23:13:05 +02:00
calixteman
efc5c3c231
Merge pull request #19862 from calixteman/bug1961423
Fix 'print to pdf' on Mac with a cid font (bug 1961423)
2025-04-25 15:11:55 +02:00
Jonas Jenwald
312c85bfd6
Merge pull request #19815 from Snuffleupagus/getMergedResources-size
Ensure that "local" /Contents stream-dict /Resources aren't empty (PR 19803 follow-up)
2025-04-25 10:46:04 +02:00