Extract XFA Data
Contents
[
Hide
]
XFA (XML Forms Architecture) forms differ from traditional AcroForms because their data is stored as XML within the PDF. In this example, the Form object from the aspose.pdf.facades module is used to bind the PDF and extract its XFA data directly into a file.
- Create an instance of pdf_facades.Form() to manage form data.
- Call ‘bind_pdf()’ to attach the source PDF containing XFA forms.
- Use ‘FileIO()’ to create a writable file stream.
- Call ’extract_xfa_data()’ to export the embedded XFA XML data.
from io import FileIO
import sys
from os import path
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
# Extract XFA Data
def export_xfa_data(infile, outfile):
"""Export XFA form data."""
# Create Form object
form = pdf_facades.Form()
# Bind PDF document
form.bind_pdf(infile)
with FileIO(outfile, "w") as stream:
# Export embedded XFA XML data to the output stream
form.extract_xfa_data(stream)