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

Render Encrypted Documents using pdf-lib js library #1601

Open
2 tasks done
Anushka-Touchcore opened this issue Feb 23, 2024 · 5 comments
Open
2 tasks done

Render Encrypted Documents using pdf-lib js library #1601

Anushka-Touchcore opened this issue Feb 23, 2024 · 5 comments

Comments

@Anushka-Touchcore
Copy link

What were you trying to do?

Hi,

I am trying to render encrypted document using pdf-js library on UI. However, it is throwing the following error:

pdf-lib.js:6475 Uncaught (in promise) Error: Input document to PDFDocument.load is encrypted. You can use PDFDocument.load(..., { ignoreEncryption: true }) if you wish to load the document anyways.

How did you attempt to do it?

I tried adding { ignoreEncryption: true } property to handle this scenario.

What actually happened?

This is just preventing the exception thrown by the library, but is not rendering the document. Is there any way we can render the encrypted document using pdf-lib js library?

What did you expect to happen?

I am expecting the encrypted pdf to be rendered using pdf-lib js library.

Note: The PDF is rendered perfectly using Postman, I am facing this issue only when rendering the pdf using pdf-lib js library.

How can we reproduce the issue?

We can try to render encrypted pdf using pdf-lib library.

Attached is the PDF file which we are trying to render.
ICF TEMP.pdf

Code:

Javascript:

const pdfDoc: any = await PDFDocument.load(existingPdfBytes, { ignoreEncryption: true });
const pdfDataUri: any = await pdfDoc.saveAsBase64({ dataUri: true });
pdfBase64.value = pdfDataUri;
document.getElementById('view-pdf').src = pdfDataUri + '#toolbar=0&navpanes=0';

HTML

<iframe id="view-pdf" style="width: 100%; height: 95%;"></iframe>

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

@themegabyte
Copy link

I have used this tool to decrypt: https://smallpdf.com/unlock-pdf#r=unlock

It has worked well for me so far with pdf-lib.

@Sharcoux
Copy link

We've added support for document decryption and other features on our fork: @cantoo/pdf-lib

The project here is not maintained anymore, so you'd probably want to switch.

@Jan-Chien
Copy link

I have used this tool to decrypt: https://smallpdf.com/unlock-pdf#r=unlock

It has worked well for me so far with pdf-lib.

thanks! it is very cool, but do you know how to use it in code like javascript ?

@themegabyte
Copy link

@Jan-Chien This PR is worth following: cantoo-scribe#54

It looks like it uses code from this fork: https://github.com/PhakornKiong/pdf-lib/tree/dev/DocEncrypt

perhaps you can try to build from this fork and load your PDF. It looks like if the document is encrypted, it will attempt to decrypt it. (looking at the written tests)

@sayo96
Copy link

sayo96 commented Jun 12, 2024

Why is this project not maintained anymore?

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

5 participants