Download password-protected PDF

Which product are you using?

PDF.js Express Viewer : 8.7.0

Detailed description of issue
I’m able to view a password-protected PDF fine by supplying the password in loadDocument. I’ve updated my downloadButton element to allow a user to download the decrypted PDF, but the downloaded file is still encrypted.

Expected behaviour
When a user is viewing the decrypted pdf and click download, I want them to be able to view the downloaded file without entering the password.

Does your issue happen with every document, or just one?
All password-protected PDFs are affected.

Code snippet

//Load document (working fine):
instance.UI.loadDocument(pdf, {
filename: “test.pdf”,
password: password,
});

// Download encrypted PDF
const options = {
document: pdf,
filename: “downloaded.pdf”,
password: password,
flags: instance.Core.SaveOptions.LINEARIZED,
downloadType: “pdf”,
};

instance.updateElement(‘downloadButton’, {
onClick: () => {
console.log(‘test options’, options);
instance.UI.downloadPdf(options);
}
})
});

Hello chuck.fields

There is no password option in the downloadPdf API, you can use: doc.removeSecurity(); instead on the underlying PDFNet Doc retrieved by: await instance.Core.documentViewer.getDocument().getPDFDoc()

Let me know of this works for you

Best regards,
Tyler Gordon
Web Development Support Engineer
PDFTron

Thanks so much Tyler. I’m getting an undefined with getPDFDoc() (I can call getDocument() and get the file name). Do you happen to have a code example that uses:

await instance.Core.documentViewer.getDocument().getPDFDoc()

Hello chuck.fields,

My apologies, that would be using the PDFTron WebViewer APIs, unfortunately for PDFJS Express we cannot, we are limited by what PDFJS can do with document manipulation. You can read more about this here: Saving a document with password protection

Best regards,
Tyler Gordon
Web Development Support Engineer
PDFTron

No worries Tyler. Actually I ended up decrypting the files through an API on the backend and sending them as a blob to PDFJS, which worked perfectly!