FDF and XFDF

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

31st May 2016
iText PDF

Switch code for this example

ImportXFDF.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.  * This example was written by Bruno Lowagie in answer to the following question:
  10.  * http://stackoverflow.com/questions/30508966/saving-xfdf-as-pdf
  11.  */
  12. package com.itextpdf.samples.sandbox.acroforms;
  13.  
  14. import com.itextpdf.forms.PdfAcroForm;
  15. import com.itextpdf.kernel.pdf.PdfDocument;
  16. import com.itextpdf.kernel.pdf.PdfReader;
  17. import com.itextpdf.kernel.pdf.PdfWriter;
  18. import com.itextpdf.layout.Document;
  19. import com.itextpdf.samples.GenericTest;
  20. import com.itextpdf.test.annotations.type.SampleTest;
  21.  
  22. import org.junit.Ignore;
  23. import org.junit.experimental.categories.Category;
  24.  
  25. import java.io.FileOutputStream;
  26.  
  27. @Ignore
  28. @Category(SampleTest.class)
  29. public class ImportXFDF extends GenericTest {
  30.     public static String DEST = "./target/test/resources/sandbox/acroforms/import_xfdf.pdf";
  31.     public static final String SRC = "./src/test/resources/pdfs/Requisition_Fillable.pdf";
  32.     public static final String XFDF = "./src/test/resources/sandbox/acroforms/data.xfdf";
  33.  
  34.     public static void main(String[] args) throws Exception {
  35.         new ImportXFDF().manipulatePdf(DEST);
  36.     }
  37.  
  38.     protected void manipulatePdf(String dest) throws Exception {
  39.         // TODO DEVSIX-526
  40.         // XfdfReader xfdf = new XfdfReader(new FileInputStream(XFDF));
  41.         PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
  42.         PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
  43.         //fields.setFields(xfdf);
  44.         form.flattenFields();
  45.         pdfDoc.close();
  46.     }
  47. }
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