galkahana / HummusJS

Node.js module for high performance creation, modification and parsing of PDF files and streams
http://www.pdfhummus.com
Other
1.15k stars 170 forks source link

Unable to recrypt files, failed to read object declaration, exepected ID = 32, found 1 #431

Open ZoharGel opened 5 years ago

ZoharGel commented 5 years ago

I'm using: hummus.recrypt(pdfReader, pdfWriter, { userPassword: userPassword, ownerPassword: ownerPassword});

To add a password on a PDF file. This works for most files but in some I get this exception:

Unable to recrypt files, check that input and output files are clear and arguments are coool

After adding the 'log' path to the recrypt options object I see the following:

PDFParser::ParseExistingInDirectObject, failed to read object declaration, exepected ID = 32, found 1 PDFDocumentHandler::CopyInDirectObject, object not found. 32

Any Idea what could cause this exception?

awied commented 5 years ago

I'm running into the same error when trying to recrypt certain PDF files in PDF v 1.7. See https://github.com/galkahana/HummusJS/issues/426. In my case im doing a plain recrypt w/o involving a password:

hummus.recrypt(pdfReader, pdfWriter)

The log produces a similar output

PDFDocumentHandler::CopyInDirectObject, object not found. 383

I can't share the PDF files to reproduce since these a client documents containing confidential information.

awied commented 5 years ago

@galkahana Unfortunately I'm not a C++ guy otherwise I would fix it by myself. But I guess this is the line in question: https://github.com/galkahana/HummusJS/blob/b699d6a01ba027428120cbe5b1c16813bed0521d/src/deps/PDFWriter/PDFDocumentHandler.cpp#L606 Recrypt is such a helpful utility and I would very much appreciate if you could take a look at this issue. It is not a common issue with PDF v1.7 though. I could mail you a sample PDF document to reproduce (can't share it openly here).