modesty / pdf2json

converts binary PDF to JSON and text, for server-side PDF processing and command-line use.
https://github.com/modesty/pdf2json
Other
1.97k stars 376 forks source link

Parse encrypted PDF file #112

Open saraht129 opened 7 years ago

saraht129 commented 7 years ago

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.

arshmakker commented 6 years ago

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 :)

queerPassenger commented 5 years ago

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 .

nei commented 5 years ago

any alternative library for reading password protected files?

arojunior commented 4 years ago

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

const pdfParser = new PDFParser();
pdfParser.setPassword(`123`);
apieceofbart commented 3 years ago

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 commented 3 years ago

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

valentinbdv commented 2 months ago

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.