Inspect digital signatures

This is a code example of iText PDF, discover more.

8th November 2015
admin-marketing

iText 5 is no longer being developed, except for security fixes. Click the following link to see an updated example for iText 7.

GetN2fromSig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Example written by Bruno Lowagie.
 */
package sandbox.security;
 
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.AcroFields.Item;
import com.itextpdf.text.pdf.PRStream;
import com.itextpdf.text.pdf.PdfDictionary;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStream;
 
import java.io.IOException;
 
/**
 *
 * @author Bruno Lowagie (iText Software)
 */
public class GetN2fromSig {
    public static final String SRC = "resources/pdfs/signature_n2.pdf";
    
    public static void main(String[] args) throws IOException {
        PdfReader reader = new PdfReader(SRC);
        AcroFields fields = reader.getAcroFields();
        Item item = fields.getFieldItem("Signature1");
        PdfDictionary widget = item.getWidget(0);
        PdfDictionary ap = widget.getAsDict(PdfName.AP);
        PdfStream normal = ap.getAsStream(PdfName.N);
        PdfDictionary resources = normal.getAsDict(PdfName.RESOURCES);
        PdfDictionary xobject = resources.getAsDict(PdfName.XOBJECT);
        PdfStream frm = xobject.getAsStream(PdfName.FRM);
        PdfDictionary res = frm.getAsDict(PdfName.RESOURCES);
        PdfDictionary xobj = res.getAsDict(PdfName.XOBJECT);
        PRStream n2 = (PRStream) xobj.getAsStream(PdfName.N2);
        byte[] stream = PdfReader.getStreamBytes(n2);
        System.out.println(new String(stream));
    }
}

Resources



Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now