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

Set BoundingBox for Images #1529

Open
2 tasks done
polizoto opened this issue Oct 20, 2023 · 1 comment
Open
2 tasks done

Set BoundingBox for Images #1529

polizoto opened this issue Oct 20, 2023 · 1 comment

Comments

@polizoto
Copy link

What were you trying to do?

I receive the "'Figure' element on a single page with no bounding box" (accessibility) error for every image in my PDF.

Bbox error

I am trying to loop through each image, capture its width and height, and set the /Bbox.

How did you attempt to do it?

I have tried using the following code:

pdfDoc.context.enumerateIndirectObjects().forEach(object => {
   const pdfObject = object[1]
   if (!(pdfObject instanceof PDFRawStream)) return
       const { dict } = pdfObject
       const type = dict.get(PDFName.of('Type'))
       if (type === PDFName.of('XObject')) {
           const subtype = dict.get(PDFName.of('Subtype'))
           if (subtype === PDFName.of('Image')) {
               const width = dict.get(PDFName.of('Width'))
               const height = dict.get(PDFName.of('Height'))
               pdfObject.dict.set(PDFName.of('BBox'), new PDFArray([new PDFNumber(0), new PDFNumber(0), new
               PDFNumber(width), new PDFNumber(height)]) )
            }
        }
})

What actually happened?

The error persists in the PDF after I try to set the Bounding Box.

What did you expect to happen?

What I would expect is for the Missing Bounding Box Error to go away.

How can we reproduce the issue?

Sample PDF:

How to Freeze Your Credit - NerdWallet.pdf

Version

1.17.1

What environment are you running pdf-lib in?

Node

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

@polizoto
Copy link
Author

Note: I am checking the PDF using the PAC 2021 (accessibility) checker.

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

No branches or pull requests

1 participant