Open saraht129 opened 7 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 :)
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 .
any alternative library for reading password protected files?
The documentation is outdated, there's a method called setPassword
in this lib.
const pdfParser = new PDFParser();
pdfParser.setPassword(`123`);
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
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
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.
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.