Working with XFA Forms
Contents
[
Hide
]
Convert XFA-to-Acroform
Try online
You can check the quality of Aspose.PDF conversion and view the results online at this link: products.aspose.app/pdf/xfa/acroform
The next code snippet demonstrates how to convert a dynamic XFA (XML Forms Architecture) form to a standard AcroForm.
Key steps include:
- Loading the input PDF document.
- Changing the form type to STANDARD.
- Saving the converted PDF to a new file.
This conversion allows for better compatibility and consistent form handling across different PDF readers and applications.
import aspose.pdf as ap
import sys
from os import path
def convert_dynamic_xfa_to_acroform(infile: str, outfile: str):
"""Convert dynamic XFA form to standard AcroForm."""
with ap.Document(infile) as document:
document.form.type = ap.forms.FormType.STANDARD
document.save(outfile)
Use of IgnoreNeedsRendering
This example demonstrates how to convert a dynamic XFA form to a standard AcroForm using Aspose.PDF for Python. The code checks if the input PDF contains an XFA form and overrides rendering if necessary. It then sets the form type to STANDARD and saves the updated PDF.
import aspose.pdf as ap
import sys
from os import path
def convert_xfa_form_with_ignore_needs_rendering(infile: str, outfile: str):
"""Convert XFA form ignoring needs rendering flag."""
with ap.Document(infile) as document:
if not document.form.needs_rendering and document.form.has_xfa:
document.form.ignore_needs_rendering = True
document.form.type = ap.forms.FormType.STANDARD
document.save(outfile)