3

Does anybody perhaps know, how I can check if a PDF is password protected by using HummusJS in NodeJS? This check needs to be done when modifying a PDF.

I am struggling to find a solution online and in the documentation.

Regards

Prasanth
  • 3,029
  • 31
  • 44
frikkievb
  • 481
  • 3
  • 11

1 Answers1

3

Ok, so I got this working, thanks to HummusJS's author.

A parser object will be able to check if a PDF is encrypted or not. To create a PDFReader object (parser object), you can use:

var pdfReader = hummus.createReader('./TestMaterials/XObjectContent.PDF');

But when trying to modify the PDF, you will get an exception that the file is busy (EBUSY).

The PDFWriter object, can actually return a PDFReader object that it is using:

var pdfReader = pdfWriter.getModifiedFileParser();

By using this pdfReader object, use the following to detect if it is password protected:

pdfReader.isEncrypted()

Ciao!

frikkievb
  • 481
  • 3
  • 11