I have a single pdf with multiple copies of the same document merged into one. I want to digitally sign each and every copy, meaning the pdf must have multiple digital signatures. I'm using endesive library in Python to digitally sign the PDF. The signature is showing as valid when I sign the document once but when I'm writing the same signature multiple times, it shows that the signature is invalid (when opening the document). Is it right to digitally sign a document multiple times and if yes, how to achieve it using Python's endesive library?
2 Answers
There is a strong difference between digital and manual signature: with a manual signature, you add a signature on a paper sheet, and you can/must separately sign each page.
With a digital signature, you sign a whole document seen as a sequence of bytes. AFAIK, there is no way to have different signatures on different parts of the document.
What is possible is to assemble the parts into a large document and then sign the final document. That final signature will be an evidence that the signer attests that the document is valid at the time they signed it, and that it has not be tampered since that point.
A common usage for multiple signature is to prove that many human beings all agree with the content of a document. In administrative processes, an employee prepares a document, signs it to marks that they are responsible for the content, and a manager signs again to mark that the document has been controlled.
In order to make multiple signatures, you must incrementally save the pdf, each time you add a signature. If you use PyMuPDF to build the document, you must save as
saveIncr()
PDF only: saves the document incrementally. This is a convenience abbreviation for doc.save(doc.name, incremental=True, encryption=PDF_ENCRYPT_KEEP).
write(garbage=0, clean=False, deflate=False, deflate_images=False, deflate_fonts=False, ascii=False, expand=0, pretty=False, encryption=PDF_ENCRYPT_NONE, permissions=- 1, owner_pw=None, user_pw=None) (Changed in v1.18.3)
PDF only: Writes the current content of the document to a bytes object instead of to a file. Obviously, you should be wary about memory requirements. The meanings of the parameters exactly equal those in save(). Chapter Collection of Recipes contains an example for using this method as a pre-processor to pdfrw.