Skip to content

Can't read attachments if they don't have a description #112

Description

@4rnoP

What were you trying to do?

Get the attachment files of a PDF document

How did you attempt to do it?

I loaded a PDF with an attachment that doesn't have a description.
Then, I ran doc.getAttachments() but it generated an exception.

What actually happened?

An exception is raised

Uncaught (in promise) TypeError: t.lookup(...) is undefined
    getSavedAttachments PDFDocument.js:878
    getSavedAttachments PDFDocument.js:845
    getAttachments PDFDocument.js:913
    genpdf test.html:25
    onclick test.html:1
PDFDocument.js:878:41

What did you expect to happen?

Successfully getting the pdf attachments. If the attachment has an associated description, the code is working as intended.

How can we reproduce the issue?

Here's a simple html page demontrating the issue: test.zip
You can generate a simple pdf with an attachment (with or without description).

After having saved a file, you can try to load it with the input element (this is because the attachments that are freshly added by pdf-lib aren't handled the same way).
In the console, you can see that a document whose attachment has a description is loaded fine while the ones that don't have a description raise an Exception.

Version

2.4.1

What environment are you running pdf-lib in?

Browser

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions