Skip to content

[Bug]: Ink tool sometimes stops working (no lines created) under iOS #20498

@josefhetteggerruby

Description

@josefhetteggerruby

Summary

I’m using pdfjs-dist to build a custom viewer that supports ink annotations, leveraging pdf_viewer.js. Here is a stripped down example project of my solution. To improve drawing reliability, I disable scrolling when the ink tool is active. However, I’ve encountered two related issues:

Issue 1: Ink annotations not committed reliably

In the current AnnotationEditorLayer implementation, ink annotations are typically committed when the layer loses focus and relatedTarget is set in the blur event.
If the layer loses focus without relatedTarget, changes are not saved to the document’s AnnotationStorage.
Attempted Fix:
I tried restoring focus to the layer when relatedTarget is missing in the blur event. This ensures changes are committed before clicking the save button (since that blur event usually has a relatedTarget).
However, this approach isn’t ideal because relatedTarget is only reliably set when tabindex is present. For example, I initially had a Vue-based “Save” button instead of a native HTML button, and clicking it immediately after adding an annotation caused the changes to be lost—the resulting PDF lacked the ink annotation.

Issue 2: Ink tool breaks after zoom on iOS

After applying the fix from Issue 1 and adding zoom functionality, testing on iOS revealed that zooming while the ink tool is active sometimes breaks the tool—no lines are drawn afterward.

Web browser and its version

Safari

Operating system and its version

iOS 18.7.2

PDF.js version

5.4.449

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

Yes

Is a browser extension

No

Steps to reproduce the problem

  1. Run demo app with "npm run dev" and open it on a device running iOS
  2. Press the toolbar button "Switch to ink tool"
  3. Zoom around using pinch gestures (pages can be skipped this way)
  4. Draw something on a random page
  5. Repeat steps 3 and 4 several times

What is the expected behavior?

The ink tool should keep drawing lines even when zooming around a lot and changing pages this way

What went wrong?

Eventually you won't be able to draw lines anymore. The ink tool stops working properly.

Link to a viewer

No response

Additional context

There also seems to be an issue when the pinch to zoom gesture ends. I some cases the pdf suddenly realigns, scrolls away or changes size shortly after the fingers stop touching the screen.
When this happens, the ink tool seems to break reliably.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions