pdf2json icon indicating copy to clipboard operation
pdf2json copied to clipboard

Parse encrypted PDF file

Open saraht129 opened this issue 8 years ago • 8 comments

Does this library support parsing of an encrypted PDF file? An PasswordException is thrown with message 'no password is given', but I can't find anywhere how to supply the password.

I am using the CLI version.

saraht129 avatar Feb 09 '17 05:02 saraht129

I feel pdf2json does not support encrypted/locked pdfs. I checked the code in ./lib/pdf.js and the password is hard coded as blank.

let parameters = {password: '', data: arrayBuffer};

PS: I might be incorrect, but only @modesty can correct me :)

arshmakker avatar Nov 21 '17 22:11 arshmakker

pdf2json would have been the best library for reading pdf if it had supported password protected pdf . Not only this library but library using this library as a dependency (such as PDF Reader : npm-pdfreader ) fails the purpose .

queerPassenger avatar Sep 09 '18 14:09 queerPassenger

any alternative library for reading password protected files?

nei avatar Aug 03 '19 19:08 nei

The documentation is outdated, there's a method called setPassword in this lib.

const pdfParser = new PDFParser();
pdfParser.setPassword(`123`);

arojunior avatar May 04 '20 21:05 arojunior

This method is problematic because it sets the password on a class not an instance - if you have multiple PDFs to read it would fail

apieceofbart avatar Sep 20 '20 09:09 apieceofbart

If anyone's interested I forked this lib and fixed that - you can now pass optional password param to loadPDF method, here's the change: https://github.com/apieceofbart/pdf2json/commit/42e8a60460a610154407e7b348a56fc379233bc8

apieceofbart avatar Sep 20 '20 10:09 apieceofbart

You can add the password while initiating the PDFParser class like so: const pdfParser = new PDFParser(null, undefined, password); https://github.com/modesty/pdf2json/blob/master/pdfparser.js#L98

I tested it in my project and it works great.

valentinbdv avatar Jun 28 '24 16:06 valentinbdv