Remove digital signatures

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

31st May 2016
admin-marketing

Switch code for this example

FlattenSignature.java
  1. /*
  2.  
  3.     This file is part of the iText (R) project.
  4.     Copyright (c) 1998-2016 iText Group NV
  5.  
  6. */
  7.  
  8. /**
  9.  * Example written by Bruno Lowagie in answer to the following question:
  10.  * http://stackoverflow.com/questions/28163159/about-visible-digital-signatures
  11.  */
  12. package com.itextpdf.samples.sandbox.acroforms;
  13.  
  14. import com.itextpdf.kernel.pdf.PdfDocument;
  15. import com.itextpdf.kernel.pdf.PdfReader;
  16. import com.itextpdf.kernel.pdf.PdfWriter;
  17. import com.itextpdf.test.annotations.type.SampleTest;
  18. import com.itextpdf.forms.PdfAcroForm;
  19. import com.itextpdf.samples.GenericTest;
  20.  
  21. import java.io.File;
  22. import java.io.FileInputStream;
  23. import java.io.FileOutputStream;
  24.  
  25. import org.junit.experimental.categories.Category;
  26.  
  27. @Category(SampleTest.class)
  28. public class FlattenSignature extends GenericTest {
  29.     public static final String DEST = "./target/test/resources/sandbox/acroforms/flatten_signature.pdf";
  30.     public static final String SRC = "./src/test/resources/pdfs/input_signed.pdf";
  31.  
  32.     public static void main(String[] args) throws Exception {
  33.         File file = new File(DEST);
  34.         file.getParentFile().mkdirs();
  35.         new FlattenSignature().manipulatePdf(DEST);
  36.     }
  37.  
  38.     @Override
  39.     protected void manipulatePdf(String dest) throws Exception {
  40.         PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
  41.         PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
  42.         form.flattenFields();
  43.         pdfDoc.close();
  44.     }
  45. }
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