Flatten XFA form losing values

Hi there,

I am trying to import XML into a XFA PDF file and then flatten the file. The import works successfully, but when I try and flatten the file, the data is lost. My code is as follows:

ServletContext context = pageContext.getServletContext();
String path = context.getRealPath( “resources” );
com.aspose.pdf.kit.License license = new com.aspose.pdf.kit.License();

FileInputStream myStream = new FileInputStream(path+"\Aspose.Pdf.Kit.lic");

license.setLicense(myStream);
System.out.println( “Evaluating date now” );
Form form = new Form(path + “\electronic_application_form.pdf”, path + “\electronic_application_form.out.pdf”);

//Create a new xml file to contain the content of the pdf.
java.io.FileInputStream xmlInputStream = new java.io.FileInputStream(
path + “\SampleFile.xml”);

//Export all the pdf fields’ value into the xml file.
form.importXml(xmlInputStream);


//Close the output xml stream.
xmlInputStream.close();
form.flattenAllFields();
form.close();

Am I doing something wrong perhaps? Please help…

Thanks,

Roy

Hi Roy,

Please share the input PDF and XML files with us, so we could investigate the issue at our end. You’ll be updated with the results accordingly.

We’re sorry for the inconvenience.
Regards,

Hi there,

Can someone help me perhaps please - thanks. Just can’t seem to get form flattening to work and keep the data. Hope aspose can actually do what I want before I make a purchase.

Thanks,

Roy

Attachments are requested.

Hi Roy,

I have reproduced this issue at my end and logged it as PDFKITJAVA-28752 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

Hi,

So Aspose can’t flatten dynamic xfa files?

Kind regards,

Roy

Hi,

Can you perhaps upload an example pdf, xml and code where you can populate a pdf with xml and flatten the file? That would be highly appreciated!

Thanks,

Roy

Hi Roy,

Such issues only occur in certain scenarios, otherwise filling the fields and flattening them shouldn’t be a problem. It is a commonly used feature and many other customers are using it successfully. However, we do need to consider the particular scenarios and that’s why I have logged this issue. We’ll update you as soon as it is resolved. In the meanwhile, you may try with some other PDF files at your end.

We’re sorry for the inconvenience. If you find any further questions, please do let us know.
Regards,