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

"Error: Input document to PDFDocument.load is encrypted ..." (but pdf.js and other readers can read the file without password) #75

Closed
2 tasks done
nicolassanmar opened this issue Nov 7, 2024 · 3 comments
Labels
bug Something isn't working needs-triage

Comments

@nicolassanmar
Copy link

What were you trying to do?

I was trying to load a document using PDFDocument.load, but it threw this Error.
The PDF document can be loaded without any issues on pdf.js and in other PDF readers.
Here is a sample document that fails to load here:

sample.pdf

How did you attempt to do it?

I downloaded my document from Adobe Sign, then uploaded it to the webapp where pdf-lib is available.
I then wanted to edit it using pdf-lib, for which I loaded the document with PDFDocument.load as I do for any other document.
This throws the error:

Error: Input document to `PDFDocument.load` is encrypted. You can use `PDFDocument.load(..., { ignoreEncryption: true })` if you wish to load the document anyways.
    at new EncryptedPDFError (webpack-internal:///./node_modules/.pnpm/[email protected]/node_modules/pdf-lib/es/api/errors.js:27:24)
    at new PDFDocument (webpack-internal:///./node_modules/.pnpm/[email protected]/node_modules/pdf-lib/es/api/PDFDocument.js:72:19)
    at Function.eval (webpack-internal:///./node_modules/.pnpm/[email protected]/node_modules/pdf-lib/es/api/PDFDocument.js:144:47)
    at step (webpack-internal:///./node_modules/.pnpm/[email protected]/node_modules/tslib/tslib.es6.js:126:23)
    at Object.eval [as next] (webpack-internal:///./node_modules/.pnpm/[email protected]/node_modules/tslib/tslib.es6.js:107:53)
    at fulfilled (webpack-internal:///./node_modules/.pnpm/[email protected]/node_modules/tslib/tslib.es6.js:97:58)

Allowing ignoreEncryption does not fix this issue, as it prevents the document from being parsed properly (it returns all blank pages).

What actually happened?

I got the error mentioned above.

What did you expect to happen?

I expected the document to load without any issues into pdf-lib.
I expected this to work as I saw this comment here, stating that this fork should have fixed the issue: Hopding#1601 (comment)

How can we reproduce the issue?

Just run PDFDocument.load() over the document I shared above (which I will share here as well).

4ffefced-d7bc-4b46-bead-28cd1710534b original.pdf

Version

2.2.3

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

@nicolassanmar nicolassanmar added bug Something isn't working needs-triage labels Nov 7, 2024
@nicolassanmar
Copy link
Author

I think I solved this issue by loading the documents by passing an empty password to the load options:

await PDFDocument.load(pdfBytes, {
            throwOnInvalidObject: true,
            ignoreEncryption: true,
            password: '',
          }),

This is confusing, as I would expect that doing this is not necessary for documents that do not have a password

@nicolassanmar nicolassanmar changed the title "Error: Input document to PDFDocument.load is encrypted ..." (but pdf.js and other readers can read the file) "Error: Input document to PDFDocument.load is encrypted ..." (but pdf.js and other readers can read the file without password) Nov 7, 2024
@Sharcoux
Copy link
Collaborator

Sharcoux commented Dec 3, 2024

I wonder if we should automatically try the empty password for encrypted documents 🤔

@Sharcoux
Copy link
Collaborator

Sharcoux commented Dec 3, 2024

No, I think that the user should be responsible to decide if they want to try the empty password or not by providing the empty string as password.

@Sharcoux Sharcoux closed this as completed Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants