Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Activating the stamp editor throws an error sometimes if the opened PDF already has an existing stamp annotation in it #19239

Closed
annyanich opened this issue Dec 18, 2024 · 0 comments · Fixed by #19311
Assignees

Comments

@annyanich
Copy link

annyanich commented Dec 18, 2024

Attach (recommended) or Link to PDF file

compressed.tracemonkey-pldi-09-23.pdf

Web browser and its version

Firefox 132.0.1 (64-bit) and Chrome Version 131.0.6778.85 (Official Build) (64-bit)

Operating system and its version

Fedora Workstation 39 x64, Linux kernel 6.11.9-100.fc39.x86_64

PDF.js version

v4.9.155 and git revisions e9c81a6 and 2df5d8f built with npx gulp generic

Is the bug present in the latest PDF.js version?

Yes

Is a browser extension

No

Steps to reproduce the problem

  1. Open the demo document. Insert a stamp annotation onto the first page.  Save/download the PDF.

  2. Open the downloaded PDF with the stamp annotation.  Scroll down a few pages, e.g. to page 4, so that page 1 is completely off-screen.  Click on the stamp tool icon in the toolbar.

An error will be thrown in the console:

Uncaught (in promise) TypeError: canvas is null

getFromCanvas http://localhost:8081/src/display/editor/tools.js:210

deserialize http://localhost:8081/src/display/editor/stamp.js:787

deserialize http://localhost:8081/src/display/editor/annotation_editor_layer.js:669

enable http://localhost:8081/src/display/editor/annotation_editor_layer.js:279

#enableAll http://localhost:8081/src/display/editor/tools.js:1754

updateMode http://localhost:8081/src/display/editor/tools.js:1626

updater http://localhost:8081/web/pdf_viewer.js:2330

set annotationEditorMode http://localhost:8081/web/pdf_viewer.js:2377

bindEvents http://localhost:8081/web/app.js:1909

dispatch http://localhost:8081/web/event_utils.js:115

bindListeners http://localhost:8081/web/toolbar.js:194

#bindListeners http://localhost:8081/web/toolbar.js:192

Toolbar http://localhost:8081/web/toolbar.js:123

_initializeViewerComponents http://localhost:8081/web/app.js:584

initialize http://localhost:8081/web/app.js:253

run http://localhost:8081/web/app.js:678

webViewerLoad http://localhost:8081/web/viewer.js:255

<anonymous> http://localhost:8081/web/viewer.js:266
  1. Scroll to the top of the document. The stamp annotation will be invisible.

What is the expected behavior?

The stamp annotation should be visible at the top of the document:
2024-12-18T20:07:44,623504272+01:00

What went wrong?

The stamp annotation is not visible at the top of the document. It's vanished.

Somehow, the canvas element that should provide the image data for the editor to use is not present where it's supposed to be in the annotation layer. I believe it is supposed to be created via AnnotationLayer.#setAnnotationCanvasMap.

Another problem occurs after the bug is triggered by following my steps above: If you try to switch tools, the other tools don't work right any more (free text, highlight, etc.). They don't do anything when you click on the document to e.g. start a new free text, add a new highlight, etc.

It appears to me that the lock #updateModeCapability.promise in AnnotationEditorUIManager may be held indefinitely after the error is thrown, as future calls to updateMode seem to hang at tools.js line 1668 (await this.#updateModeCapability.promise;). This seems to make it impossible to change tools after the error occurs.

2024-12-18T20:12:22,596034416+01:00
2024-12-18T20:12:38,542374488+01:00

Link to a viewer

No response

Additional context

This error appears to be present in the original commit where the feature to edit existing stamp annotations was introduced, e9c81a6e, as well as the current HEAD of the development branch, 2df5d8f3.

A side note:
I am accessing my PDF.js over Python's simple HTTP server using the following script:
simpleserver.txt
(I have renamed it to txt to bypass github's file type filter.)
I am curious how you all do it on your local machines and would be grateful for any tips on how to set up my local dev environment effectively outside of what's mentioned in the README.
All the best,
Ann

@calixteman calixteman self-assigned this Jan 9, 2025
calixteman added a commit to calixteman/pdf.js that referenced this issue Jan 9, 2025
…visible existing stamp editor

It fixes mozilla#19239.

When the canvas isn't existing the editor has no image: it's fine because the editor is invisible.
Once it's made visible, the canvas is set when the annotation layer has been rendered.
calixteman added a commit to calixteman/pdf.js that referenced this issue Jan 9, 2025
…visible existing stamp editor

It fixes mozilla#19239.

When the canvas isn't existing the editor has no image: it's fine because the editor is invisible.
Once it's made visible, the canvas is set when the annotation layer has been rendered.
calixteman added a commit to calixteman/pdf.js that referenced this issue Jan 10, 2025
…visible existing stamp editor

It fixes mozilla#19239.

When the canvas isn't existing the editor has no image: it's fine because the editor is invisible.
Once it's made visible, the canvas is set when the annotation layer has been rendered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants