Issue to create XFA form using XFA form template and xml data file via Aspose.pdf for Java

Hello,



I want to create a XFA form with corresponding data in it. Below are what I have as inputs.

1. XFA form template: B6I_xfa_Template.pdf created via Adobe Live Cycle Designer

2. xml data file: B6I_data_xml.xml



I used the following way to fill the xml data into the template to create the xfa form.



public class FillXfa2 {

public static final String TEMPLATE = “C:\temp\xfa\createStretch\B6I_xfa_Template.pdf”;

public static final String SRC_XML = “C:\temp\xfa\createStretch\B6I_data_xml.xml”;

public static final String DEST = “C:\temp\xfa\createStretch\B6I_xfa_filled_via_aspose.pdf”;



public static void main(String[] args) throws FileNotFoundException {

ApplyLicense.setLicense();

fillXfa();



}



private static void fillXfa() {

Document document = new Document(TEMPLATE);

document.getForm().setType(FormType.Dynamic);

document.bindXml(SRC_XML);

document.save(DEST);

}

}



B6I_xfa_filled_via_aspose.pdf does NOT contain any data.



Then I used the iText core API to fill the data to the template. Then B6I_xfa_filled_via_iText.pdf contains the correct data.



What is the right way to fill the data via Aspose.pdf for Java?



All the input and output files mentioned are attached.



Thanks.



Jeff

Hi Jeff,


Thanks for your inquiry. Please note importXml method of com.aspose.pdf.facades.Form class is used to import XML data into Form template. However I am afraid it is not working as expected with your PDF template, so I have logged a ticket PDFJAVA-36167 for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry the inconvenience.

Best Regards,

Hi Jeff,

Thanks for using our API’s.

Adding more to Tilal’s observations, please note that bindXml(…) method of Document class is used to transform XML file to PDF format and in order to fill form template with data from XML file, you need to try using importXml(…) method of com.aspose.pdf.facades.Form class. The following code snippet shows the steps to fill XML data into Form template. But as the API is having issues, so currently this method do not work. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

[Java]

com.aspose.pdf.facades.Form form = new com.aspose.pdf.facades.Form();
form.bindPdf("c:/pdftest/B6I_xfa_Template.pdf");

// Create XML file.
java.io.FileInputStream xmlInputStream = new FileInputStream("c:/pdftest/B6I_data_xml.xml");

// Export data
form.importXml(xmlInputStream);

// Close file stream
xmlInputStream.close();

form.save("c:/pdftest/FilledPDFFile.pdf");

// Dispose the form object
form.dispose();

The issues you have found earlier (filed as PDFJAVA-36167) have been fixed in Aspose.Pdf for Java 17.3.0 Release Notes.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.