ImageGear PDF v25.2 - Updated
XFA Support
Developer Guide > How to Work with... > PDF > How to... > Work with PDF Forms > XFA Support

ImageGear for .NET has limited support for PDF documents containing XFA forms.

Enabling XFA

By default, loading a PDF document that contains XFA data will throw an exception and the document will not be loaded since special consideration is needed on how to treat such a document (see below).

In order to enable opening of PDF documents containing XFA data, you first have to add the PDF filter, then initialize the PDF engine, and finally set the corresponding control parameter XFAAllowed to true:

C#
Copy Code
// Initialize support for common formats.
ImGearCommonFormats.Initialize();

// Add PDF file format filter to filter list.
ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePDFFormat());

// Initialize PDF engine.
ImGearPDF.Initialize();

// Allow opening of PDF documents that contain XFA form data.

IImGearFormat format = ImGearFileFormats.Filters.Get(ImGearFormats.PDF);
format.Parameters.GetByName("XFAAllowed").Value = true;

Note that if your program reuses the PDF format filter after calling ImGearPDF.Terminate() you will need to remove the PDF filter from the list of filters and then once again add it in:

C#
Copy Code
// Initialize support for common formats.
ImGearCommonFormats.Initialize();

//Check for pre existing PDF Formats
if (!ImGearFileFormats.Filters.Contains(ImGearFormats.PDF))
{
// Add PDF file format filter to filter list. ImGearFileFormats.Filters.Insert(0,ImGearPDF.CreatePDFFormat(PDFBinaryPath));
}

else
{
// Remove then insert filters from list so that the XFA property can fully reinitialize
ImGearFileFormats.Filters.Remove(ImGearFormats.PDF);
ImGearFileFormats.Filters.Insert(0, ImGearPDF.CreatePDFFormat(PDFBinaryPath));
}

// Initialize PDF engine.
ImGearPDF.Initialize();

// Allow opening of PDF documents that contain XFA form data.
IImGearFormat format = ImGearFileFormats.Filters.Get(ImGearFormats.PDF);
format.Parameters.GetByName("XFAAllowed").Value = true;

 

Rendering XFA

PDF documents containing XFA come in different flavors: dynamic and static. Currently, ImageGear for .NET does not support rendering of dynamic XFA content. Usually, a placeholder page with a warning message that is present in the document will be rendered instead. Documents containing static XFA will usually render correctly since the XFA information is duplicated in the PDF as Acroform fields and/or content, and XFA data is simply ignored.

Modifying Forms

Since XFA data is currently largely ignored by ImageGear, changing form fields by means of the ImGearPDFDocument.Form and related objects will not update the XFA data, and these will become out of sync with the Acroforms data. Fields and their widgets should therefore not be added, removed, modified, flattened or filled in.

The only valid operation on a form when XFA is present is the flattening of the whole form using ImGearPDFDocument.FlattenFormFields(). This will flatten any Acroform fields and remove the Form, including any XFA data.

Detecting and Removing XFA

ImageGear for .NET allows you to determine whether a document has XFA and also whether it is dynamic or static, using the property ImGearPDFDocument.XFAContentType. Complete removal of the XFA data can be done using the method ImGearPDFDocument.RemoveXFA(). This will not change any Acroform data.

Is this page helpful?
Yes No
Thanks for your feedback.