Communication-Systems-Group / pdfsign.js

96 stars 26 forks source link

Invalid PDF is formed for some PDFs #5

Open nradosevic opened 5 years ago

nradosevic commented 5 years ago

For some PDFs, the resulting signed PDF is corrupted. I can't remember exactly how I got this PDF, but I think I used some PDF to word conversion service like https://www.pdftoword.com/en/. Probably PDF that is formed by the PDF to word converter has something strange and non-standard in it's structure, and then when the document is prepared for signing something goes wrong. On the other hand, when I try to sign this PDF using some other library like for ex. Apache PDFBox for Java, it's working fine, so that means that this library could be readjusted to make it work with PDFs like this one.

Here's a PDF that I'm talking about: http://www.filedropper.com/contract

nradosevic commented 5 years ago

After debugging I found out that the PDF gets corrupted after appending the acro form. So, it gets corrupted after this line 405 - var array = insertIntoArray(pdf.stream.bytes, offsetForm, appendAcroForm);