PDFium Delphi Component Docs

ExportXFDF method

Component: TPdf  ·  Unit: PDFium
Serialises every form field value and annotation across all pages of the loaded document into an XFDF (ISO 19444-1) document, written as UTF-8 XML with the http://ns.adobe.com/xfdf/ namespace.

Syntax

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

Description

ExportXFDF walks every page of the loaded document and produces an ISO 19444-1 conformant XFDF document rooted in the http://ns.adobe.com/xfdf/ namespace. The output consists of a <fields> section and an <annots> section, both emitted as UTF-8 XML.

For form fields, the method enumerates the widget annotations of every page, reads each field value, and writes a <field> element. Hierarchical (qualified) field names are split on the dot separator and emitted as nested <field> elements so that the parent/child structure round-trips. Checkboxes and radio buttons export their export value (the appearance-state name that represents the on state) as the field value. Signature fields are listed but their value is never exported.

Value-presence flags keep an explicitly empty field value distinct from an omitted value, including fields nested more than two levels deep

For annotations, every non-widget, non-popup annotation on every page is serialised. The exporter recognises 18 /Subtype values: text, highlight, underline, strikeout, squiggly, line, circle, square, caret, polygon, polyline, stamp, ink, freetext, fileattachment, sound, link, and redact. Each is written as an element under <annots> carrying its page index, bounding rectangle, contents, title (author), name (NM), subject, modification and creation dates, flags, and colour.

Encoding conventions follow ISO 19444-1: colours are written as #RRGGBB hex strings; coordinate lists (rectangle, line endpoints, polygon/polyline vertices, ink lists) are comma-separated numbers; and annotation flags are emitted as a comma-separated list of flag names rather than a raw bitmask.

For multi-line markup annotations, the coords attribute includes every quadrilateral in document order rather than only the first line

Annotation content uses the same presence semantics, so an explicit empty contents element survives export without turning an absent element into an empty one

PDFium itself exposes no XFDF API. ExportXFDF is implemented entirely in Pascal by PDFium Delphi Component on top of its own annotation and form-field data model, querying PDFium only for the per-annotation attribute values.

Returns the number of UTF-8 bytes written. The Stream overload accepts a TStream to write into; the FileName overload accepts a file path and creates/truncates that file. ExportXFDFToStream is an alias for the Stream overload.

Remarks

Example

// Export all fields and annotations to an .xfdf file
BytesWritten := Pdf1.ExportXFDF('C:\Data\form.xfdf');

// Or to a stream
var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create('C:\Data\form.xfdf', fmCreate);
  try
    Pdf1.ExportXFDF(Stream);
  finally
    Stream.Free;
  end;
end;

See Also

ImportXFDF, Annotation, AnnotationCount, FormFieldInfo