#1260·pdf-lib

Expected instance of PDFDict, but got instance of undefined

Author: dinobalCreated Jun 27, 2022Updated May 24, 2026
Labelsbugneeds-triage

What were you trying to do?

Getting indices, pages or a page by index throws this error. Cant share the document but because of sensitive data. It has Page Extraction: Not Allowed and Document Assembly: Not Allowed but that doesn't prevent other PDFs working just fine.

How did you attempt to do it?

Simple and straight forward

const attachedPDF = await PDFDocument.load(existingPdfBytes, { ignoreEncryption: true });
const pageIndices = attachedPDF.getPageIndices();

What actually happened?

Works most of the time but invoice PDFs from a specific client are not ok. It always throws Expected instance of PDFDict, but got instance of undefined when this const pageIndices = attachedPDF.getPageIndices(); or this const pages = attachedPDF.getPages(); is executed...

If I open it in Edge and add some text and save it as changed doc. The changed doc works without issues.

What did you expect to happen?

Get information about pages.

How can we reproduce the issue?

I can not make the document public as its an invoice but can ask for permission to send it privately if necessary. Editing information fixes the issue which makes it hard to erase sensitive data. e.g. Editing in MS Edge (just adding text) fixes the issue.

Version

1.17.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