Page 1 of 1

PDF file loaded and saved seems to be modified

Posted: Thu Dec 27, 2018 7:15 pm
by nenea
Hi all,
I noticed that simply opening and saving a PDF file results in a modified file.

Example:
In filePath there is a signed PDF. Opening with Acrobat Reader validate the signature.

Then
GdPicturePDF _oGdPicturePDF = new GdPicturePDF();
_oGdPicturePDF.LoadFromFile(filePath, false);

_oGdPicturePDF.SaveToFile(newPath, false, true);


The saved file seems to be changed and the signature is not verified by Acrobat Reader.
I tried with linearize parameter true or false.

Am I doing something wrong?

Thank you very much
Nazareno

Re: PDF file loaded and saved seems to be modified

Posted: Fri Dec 28, 2018 11:38 am
by nenea
Solved by myself.

Using SaveToFileInc did the work.

Re: PDF file loaded and saved seems to be modified

Posted: Wed Jan 16, 2019 4:58 pm
by Matus
Hi,

This is correct behavior. GdPicture needs to parse the document upon loading it. In some cases in order to open the file we need to repair the files. Because of that saving the file will automatically reconstruct the PDF file. Digital signatures make sure there have not been any modifications in the file. Even single different byte will lead to invalid signature because the document hash will be different.

You have correctly used the SaveToFileInc. This method keeps the document data unchanged and any modifications are appended at the end of the file. This is a feature of PDF format. Without any modification the document and file data will be unchanged and the Digital Signature will be valid. In case there are modifications the file will hold separate document versions and the Digital Signature will be able to verify the version that was signed.