Why does saving invalidate an existing digital signature?

Question:

I have a pdf with a valid digital signature, after loading and saving the pdf by:

string path = "signed_pdf_document.pdf"; using (PDFDoc doc = new PDFDoc(path)) { doc.Save(path + "e_remove_unused.pdf", SDFDoc.SaveOptions.e_remove_unused); }

The digital signature get invalidated.

What do I have to do for preserving the digital signature validation?

Answer:

You need to save using Incremental save mode. The other save modes potentially modify the original bytes of the PDF, which will invalidate the signatures.

doc.Save(path + "e_incremental.pdf", SDFDoc.SaveOptions.e_incremental);

Note, you can call PDFDoc.HasSignatures to check if you need to save incrementally or not.

These posts provide more details.

https://groups.google.com/d/msg/pdfnet-sdk/yNbgF7Ds5ZI/jOb5xiRFDQAJ

https://groups.google.com/d/msg/pdfnet-sdk/h_zoSC-2HOo/D1kFzcHhDQAJ