Skip to content

[Bug]: Saving fails after marking an existing image as decorative #22128

Description

@AlexAndBear

Attach (recommended) or Link to PDF file

Any PDF, e.g. the default compressed.tracemonkey-pldi-09.pdf of the viewer (the steps create the image).


Web browser and its version

Chromium 153

Operating system and its version

macOS 26.5

PDF.js version

6.4.299 (generic viewer from the pdfjs-dist release)

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

Yes

Is a browser extension

No


Steps to reproduce the problem

  1. Open a PDF in the viewer, add an image ("Add image"), click "Alt text" on it, enter a description (e.g. "A castle") and save the dialog.
  2. Download the PDF and open the downloaded file.
  3. Double-click the image to edit it, click "Alt text": the description "A castle" is shown. Check "Mark as decorative" and save the dialog.
  4. Download the PDF again.

What is the expected behavior?

The PDF is saved, with the image marked as decorative (or without its alt text).

What went wrong?

Saving fails, the console shows:

Error when saving the document: TypeError: Cannot set properties of undefined (setting 'structParent')
    at StampEditor.serialize (pdf.mjs:26653:51)
    at get serializable (pdf.mjs:6960:64)
    at WorkerTransport.saveDocument

annotationStorage.serializable throws from then on, so no other change in the document can be saved either.

In StampEditor.serialize, accessibilityData is only set for a non-decorative image with an alt text:

if (!decorative && altText) {
  serialized.accessibilityData = { type: "Figure", alt: altText };
}
if (this.annotationElementId) {
  ...
  if (changes.isSameAltText) {
    delete serialized.accessibilityData;
  } else {
    serialized.accessibilityData.structParent = this._initialData.structParent ?? -1;
  }

For an existing image whose alt text changed to decorative (or was removed), serialized.accessibilityData is undefined when structParent is set.

Link to a viewer

No response

Additional context

We use PDF.js' editors in an editor for PDFs in OpenCloud (opencloud-eu/web-extensions#618), where the failing serialization meant that later changes weren't recognized at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions