trying to remove a signature from pdf file

Previous Topic Next Topic
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

trying to remove a signature from pdf file

Massa Alfonso


I'm trying to remove a signature from the attached sample PDF with itextpdf 5.5.8 and save the result in another file using this java code:


                               Provider provider = new BouncyCastleProvider();



                               PdfReader reader = new PdfReader(inputStream, null);

                               AcroFields af = reader.getAcroFields();

                               ArrayList<String> names = af.getSignatureNames();

                               for (String name : names) {

                                   System.out.println("Signature name: " + name);

                                   System.out.println("Signature covers whole document: " + af.signatureCoversWholeDocument(name));

                                   PdfPKCS7 pk = af.verifySignature(name, provider.getName());

                                   System.out.println("SignatureDate: " + pk.getSignDate());

                                   System.out.println("Certificate: " + pk.getSigningCertificate());

                                   System.out.println("Document modified: " + !pk.verify());



                               PdfStamper stamper = new PdfStamper(reader, outputStream, '\0');



But I have this exception in removeField:

Exception in thread "main" java.lang.NullPointerException

      at com.itextpdf.text.pdf.AcroFields.removeField(AcroFields.java:1814)

      at com.itextpdf.text.pdf.AcroFields.removeField(AcroFields.java:1854)

      at securityframe.cms.VerificaFirmaCerta.verify(VerificaFirmaCerta.java:47)

      at securityframe.cms.VerificaFirmaCerta.main(VerificaFirmaCerta.java:67)


The attached file is signed with FirmaCerta (a italian sw).

Anyone can help me? There is a bug in the signature sw or in the itext library?


Thanks in advance.




AVVISO DI RISERVATEZZA Informazioni riservate possono essere contenute nel messaggio o nei suoi allegati. Se non siete i destinatari indicati nel messaggio, o responsabili per la sua consegna alla persona, o se avete ricevuto il messaggio per errore, siete pregati di non trascriverlo, copiarlo o inviarlo ad alcuno. In tal caso vi invitiamo a cancellare il messaggio ed i suoi allegati. Grazie.
CONFIDENTIALITY NOTICE Confidential information may be contained in this message or in its attachments. If you are not the addressee indicated in this message, or responsible for message delivering to that person, or if you have received this message in error, you may not transcribe, copy or deliver this message to anyone. In that case, you should delete this message and its attachments. Thank you.
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
iText-questions mailing list
[hidden email]

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php

PDFSignedFirmaCerta.pdf (42K) Download Attachment
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Re: trying to remove a signature from pdf file

Massa Alfonso wrote
Anyone can help me? There is a bug in the signature sw or in the itext library?
The signature field claims it has a widget annotation on the page represented by the object 1 0 indicated by the form field type Annot and subtype Widget (which means that this form field dictionary has a single widget annotation dictionary merged into it) in combination with the P value (by which an annotation points to its page object).

21 0 obj
/FT /Sig
/T (firmacertasign_1)
/Type /Annot
/Subtype /Widget
/F 132
/P 1 0 R
/AP <<
>>/Rect [
]/V 22 0 R

On the other hand the referenced page dictionary claims not to have any annotations as it has no Annots array:

1 0 obj
<</Type /Page/Parent 6 0 R/Resources 13 0 R/MediaBox [0  0  595  842 ]/Group <</S /Transparency/CS /DeviceRGB/I true>>/Contents 2 0 R>>

This structure is questionable and suspect even if the specification may be read in a way to call this valid (Annots is an optional page entry but commonly it is assumed that it is optional only if the page has no annotations).

The method AcroFields.removeField(String, int) hickups when confronted with such a situation:

            int pageV = item.getPage(k).intValue();
            if (page != -1 && page != pageV)
            PdfIndirectReference ref = item.getWidgetRef(k);
            PdfDictionary wd = item.getWidget( k );
            PdfDictionary pageDic = reader.getPageN(pageV);
            PdfArray annots = pageDic.getAsArray(PdfName.ANNOTS);

If a form field is not referenced from any document page, pageV is -1, so pageDic is null and pageDic.getAsArray results in a NullPointerException.

To answer your question, therefore, this a a dubious construct created by the signature software which then is processed by iText code not sufficiently defensively programmed.

Regards,   Michael