I used the function from the following link to remove all the signatures from a pdf.
What I got was a pdf without the signatures but with their visual representation in the pdf content. Isn't there a function that removes the visual representation too ?
I need this because I want to calculate the hash of the original pdf. Thanks !
You claim: I used this function from the following link to remove all the signatures from a PDF, but that example isn't meant to remove the signatures, it's meant to flatten the signatures (the example is called FlattenSignatures
).
Flattening means that the signature field is removed (the signature is gone), but that the corresponding widget annotation (the visual representation as you call it) is preserved.
If you want to remove a signature field and its widget annotations, you need to remove the field:
PdfReader reader = new PdfReader(src);
AcroFields acroFields = reader.getAcroFields();
acroFields.removeField("my_signature_name");
PdfStamper stamper = new PdfStamper(reader, dest);
stamper.close();
reader.close();
However, you claim I need this because I want to calculate the hash of the original pdf. That is totally wrong. Removing the signature won't result in the original PDF!
If you want to verify the signature, you should extract the byte range from the PDF as defined in the signature dictionary. See Verifying digital signatures in PDF documents. Note that you have asked this question before, and that it was already adequately answered: iText verify integrity of a pdf in java.
Unless the signature was added in append mode (something I wouldn't assume if I were you), there is no way for you to get the original PDF. Do you know if the signature was added in append mode? If so, please add this information to your question.