Open dinobal opened 2 years ago
+1
+1
+1
Hello,
I have the same issue and can't figure out what's the problem. Of course, it's a sensitive pdf file so I can't share it
const pdf = await PDFDocument.load(buffer, { ignoreEncryption: true });
const pageCount = pdf.getPageCount();
+1
Here is an issue with an example PDF that causes this error: https://github.com/nbesli/pdf-merger-js/issues/120
I hope this helps!
I was having the same issue, and it was due to PDFs not being PDF/A compliant.
https://github.com/Hopding/pdf-lib/issues/623#issuecomment-724654427
+1
+1
+1
+1
This is likely due to the pdfs being encrypted. You can tell by the (SECURED)
message when opening in a pdf reader app (not the browser). See: https://www.quora.com/How-would-I-know-if-a-PDF-document-is-password-protected
I'm having the same issue with my encrypted/secured pdfs.
NOTE: Just because it's a secure pdf, doesn't mean it necessarily requires a password. Here is an example from my PDF:
(screenshot from Foxit Reader)
Depending on your use case you may be able to use a fork of this repo as described here since that appears to have encrypted pdf support: https://github.com/Hopding/pdf-lib/issues/1616
I haven't figured out a good solution for this at scale, but if it's a small batch of pdfs, you can probably open them in a pdf reader, then print as a pdf to make a new one, then run your processing on that.
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
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 thisconst 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
Additional Notes
No response