PDFium Component Docs

ImportXFDF method

Component: TPdf  ·  Unit: PDFium
Reads an XFDF (ISO 19444-1) document and applies its form field values and annotations to the loaded PDF, creating annotations on the matching pages and writing field values into their widget annotations.

Syntax

function ImportXFDF(const FileName: string): Integer; overload;
function ImportXFDF(Stream: TStream): Integer; overload;

Description

ImportXFDF parses the XFDF XML document and applies its <fields> and <annots> sections to the currently loaded PDF.

For each <field> element, the qualified (dotted) name is matched against the widget annotations in the document and the value is written into the field's /V entry. For checkbox and radio-button fields, the supplied export value is used to select the matching on-state appearance, so the field is rendered as checked.

For each annotation element, a new annotation is created on the page indicated by the page attribute (0-based). After creation, the importer fills in Contents, Author (title), Name (NM), Subject, ModificationDate, CreationDate, Icon, and the annotation flags from the corresponding XFDF attributes.

Returns the total number of fields and annotations processed.

The rect attribute is mandatory for every annotation: if it is missing, the annotation is skipped rather than created with a zero-size rectangle.

Parsing is performed by a hand-written XML scanner rather than a full XML DOM, so ImportXFDF introduces no XML DOM dependency.

Remarks

Example

// Import field values and annotations from an .xfdf file
Imported := Pdf1.ImportXFDF('C:\Data\form.xfdf');
Pdf1.SaveAs('C:\Data\form_filled.pdf');

See Also

ExportXFDF, CreateAnnotation, Annotation, FormFieldInfo