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

Expected instance of PDFDict, but got instance of undefined #1260

Open
2 tasks done
dinobal opened this issue Jun 27, 2022 · 13 comments
Open
2 tasks done

Expected instance of PDFDict, but got instance of undefined #1260

dinobal opened this issue Jun 27, 2022 · 13 comments

Comments

@dinobal
Copy link

dinobal commented Jun 27, 2022

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

@dreinon
Copy link

dreinon commented Jul 18, 2022

+1

2 similar comments
@quiquelhappy
Copy link

+1

@JeffJankowski
Copy link

+1

@iGitScor
Copy link

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();

@ansnoussi
Copy link

+1

@nicolofranceschi
Copy link

  • 1

@mojoaxel
Copy link

mojoaxel commented Sep 4, 2023

Here is an issue with an example PDF that causes this error:
nbesli/pdf-merger-js#120

I hope this helps!

@pheidler
Copy link

I was having the same issue, and it was due to PDFs not being PDF/A compliant.

#623 (comment)

@SimonRenault86
Copy link

SimonRenault86 commented Dec 18, 2023

+1

3 similar comments
@longgtruong
Copy link

+1

@PastaMista
Copy link

+1

@andefran
Copy link

+1

@davidstackio
Copy link

davidstackio commented Jun 16, 2024

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:

image
(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: #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.

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