XFA to PDF Acroform

Any operations on Dynamic PDF (XFA), is limited to only first 2 pages. Is this a limitation or any option is available to achieve flattening of all pages of Dynamic pdf.

@SwethaRaj

When working with dynamic PDFs (XFA forms), it’s important to understand that operations are often limited to the first two pages due to the inherent nature of XFA. This limitation affects the ability to flatten or manipulate all pages of a dynamic PDF.

To resolve this issue and achieve flattening of all pages, you should convert the XFA form to a static PDF format first. This can be accomplished using Aspose.PDF, which provides functionality to convert XFA to a standard PDF. Once the conversion is complete, you can then flatten the entire document without any page limitations.

Here’s a basic example of how to convert an XFA PDF to a standard PDF:

// Load the XFA document
Document pdfDocument = new Document("input.xfa");

// Save as a standard PDF
pdfDocument.Save("output.pdf");

After the conversion, you can proceed to flatten the PDF as needed. If you have any further questions or require assistance with specific code, please don’t hesitate to ask.

I hope this solution works for you!

public byte[] flattenXFAForm(byte[] contents) {
try (ByteArrayOutputStream op = new ByteArrayOutputStream()) {
com.aspose.pdf.Document document = new com.aspose.pdf.Document(contents);
document.getForm().setType(FormType.Standard);
document.flatten(); // limited to Only 2 page
// document.getForm().flatten(); /// limited to only 2 page
// Form form = new Form(document);
// form.exportXml(new FileOutputStream(“C:\Sample_forms\acroform_output.xml”)); // Limited to only 2 page
document.save(op);
contents = op.toByteArray();
} catch (Exception e) {
return null;
}
return contents;
}

Even converting to standard/static is not working. Any operations are limited to only first 2 pages

@SwethaRaj

Have you tested while applying a valid or 30-days free temporary license before trying the conversion? In case you are still noticing any issues, please share your sample PDF document with us. We will test the scenario in our environment and address it accordingly.

Yes a valid Aspose Total license is applied.

@SwethaRaj

In that case, would you please share your sample PDF document (as requested earlier) so that we can test the scenario in our environment and address it accordingly?

Empty_Medwatch Form.pdf (199.3 KB)

Here the third page will not be included if document.flatten() is invoked

@SwethaRaj

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-45320

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.