Import and Export into XFDF

Skip to end of metadata
Go to start of metadata
What is XFDF?

XFDF stands for XML Forms Data Format. In our previous topics, we have learnt that it is possible to import or export PDF form data to or from an XML or FDF file. Aspose.Pdf.Kit provides the flexibility to also use an XFDF file for the same purpose.

XFDF is an XML based subset of FDF for representing form data and annotations that are contained in a PDF form. The procedure to use an XFDF file is similar to XML and FDF with some minor changes that would be more visible with the help of information given below with examples.

Export Pdf Form Fields Into XFDF

To export the contents of the PDF form fields, Aspose.Pdf.Kit provides a Form class and the path of the input PDF document is passed to its constructor as a parameter. Once then PDF document is loaded then ExportXfdf method of the Form class is called, which exports all values for the PDF form fields in the input PDF document to an XML file. The output XML file is passed to the ExportXfdf method as a FileStream instance. Please refer to the example given below for the demonstration purposes.

[Java]
//Call the custructer of Form.
Form form = new Form();

//Export all the pdf fields' value into the xfdf file.
form.exportXfdf(path + "OnlineFilled.pdf", path + "Online.xfdf");

//Close the output xfdf stream.
xfdfOutputStream.close();

form.close();
 
Import XFDF Contents Into Pdf Form Fields

To import the values of the PDF form fields back to the PDF document, we will again make use of Form class. This time, we will pass the storage paths of an input PDF document and an output PDF document (which will be generated after values imported to it) to the constructor of the Form class. After that, ImportXfdf method of the Form class is called, which imports all values of the PDF form fields (stored in the XFDF file) back to the output PDF document. The input XFDF file is passed to the ImportXfdf method as a FileStream instance. After the values are exported to the output PDF document, Save method of the Form class is called to save the output PDF document with values added to it. Please refer to the example given below for the demonstration purposes.

[Java]
//Assign an input and output pdf file.
Form form = new Form(path + "Online.pdf", path + "OnlineXfdfout.pdf");

//Import the xfdf content into the pdf file.
form.importXfdf(path + "Online.xfdf");

//Save the output file.
form.close();
 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.