Inspect digital signatures

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

8th November 2015
admin-marketing

Switch code for this example

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

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