Flattening a form

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

23rd December 2015
admin-marketing

Switch code for this example

CheckBoxFlatten.java
  1. /*
  2.  * Example written by Bruno Lowagie in answer to:
  3.  * http://stackoverflow.com/questions/34439850
  4.  */
  5. package sandbox.acroforms;
  6.  
  7. import com.itextpdf.text.DocumentException;
  8. import com.itextpdf.text.pdf.PdfReader;
  9. import com.itextpdf.text.pdf.PdfStamper;
  10. import java.io.File;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13. import sandbox.WrapToTest;
  14.  
  15. /**
  16.  *
  17.  * @author Bruno Lowagie (iText Software)
  18.  */
  19. @WrapToTest
  20. public class CheckBoxFlatten {
  21.    
  22.     public static final String SRC = "resources/pdfs/checkboxes.pdf";
  23.     public static final String DEST = "results/acroforms/checkboxes_flat.pdf";
  24.    
  25.     public static void main(String[] args) throws DocumentException, IOException {
  26.         File file = new File(DEST);
  27.         file.getParentFile().mkdirs();
  28.         new CheckBoxFlatten().manipulatePdf(SRC, DEST);
  29.     }
  30.     public void manipulatePdf(String src, String dest) throws DocumentException, IOException {
  31.         PdfReader reader = new PdfReader(src);
  32.         PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
  33.         stamper.setFormFlattening(true);
  34.         stamper.close();
  35.     }
  36. }
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