Why does saving invalidate an existing digital signature?


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?


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.