PDFium Delphi 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.

An explicitly empty <value> clears the matching field, while an omitted value leaves it unchanged; deeply nested dotted field names retain their full hierarchy

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.

Annotation import applies RGB and interior colors, preserves explicit empty text fields, parses decimal coordinates independently of the process locale, and restores every markup quadrilateral from the coords attribute

The scanner accepts namespace-prefixed elements and attributes, mixed text and CDATA nodes, XML entity references, and whitespace-significant field or annotation content; invalid numeric Unicode scalar references reject the XFDF input

An omitted annotation contents element leaves the new annotation's content absent, while an explicit empty element writes an empty value

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