PDFium Delphi Component Docs

FPdfXfdf unit

Unit: FPdfXfdf
Standalone XFDF and FDF import and export that serializes form fields and annotations without loading pdfium.dll

Syntax

TXfdfField = record
  Name: XFDFString;
  Value: XFDFString;
  HasValue: Boolean;
  Children: array of TXfdfField;
  Values: TXfdfWideStrings;
  RichText: XFDFString;
  HasRichText: Boolean;
end;

TXfdfExportOptions = record
  SourceFileName: AnsiString;
  FileIdOriginal: AnsiString;
  FileIdModified: AnsiString;
  NamespaceAttributes: TXfdfNameValuePairs;
end;

TXfdfImportResult = record
  Fields: TXfdfFieldArray;
  Annotations: TXfdfParsedAnnotationArray;
  SourceFile: AnsiString;
  FileIdOriginal: AnsiString;
  FileIdModified: AnsiString;
  NamespaceAttributes: TXfdfNameValuePairs;
end;

TFdfImportResult = record
  Fields: TXfdfFieldArray;
  SourceFile: XFDFString;
end;

function XfdfExportToStream(Stream: TStream; const Fields: array of TXfdfField;
  const Annotations: array of TXfdfAnnotationExport;
  const Options: TXfdfExportOptions;
  const SubtypeToElementName: array of AnsiString): Integer;
function XfdfExportToFile(const FileName: string; const Fields: array of TXfdfField;
  const Annotations: array of TXfdfAnnotationExport;
  const Options: TXfdfExportOptions;
  const SubtypeToElementName: array of AnsiString): Integer;
function XfdfImportFromStream(Stream: TStream): TXfdfImportResult;
function XfdfImportFromFile(const FileName: string): TXfdfImportResult;
function FdfExportToStream(Stream: TStream; const Fields: array of TXfdfField;
  const SourceFileName: AnsiString = ''): Integer;
function FdfExportToFile(const FileName: string; const Fields: array of TXfdfField;
  const SourceFileName: AnsiString = ''): Integer;
function FdfImportFromStream(Stream: TStream): TFdfImportResult;
function FdfImportFromFile(const FileName: string): TFdfImportResult;
function XfdfFindAttribute(const Annot: TXfdfParsedAnnotation;
  const Name: AnsiString; out Value: AnsiString): Boolean;
function XfdfFindAttr(const Attrs: TXfdfNameValuePairs;
  const Name: AnsiString; out Value: AnsiString): Boolean;

Description

FPdfXfdf provides the Pascal-level XFDF and FDF data model and serialization. It is the engine behind TPdf.ExportXFDF, TPdf.ImportXFDF, TPdf.ExportFDF, and TPdf.ImportFDF, but it can also be used directly without an open PDF

XFDF export and import exchange field values and annotations through UTF-8 XML, while FDF export and import exchange the shared field tree through ISO 32000 PDF-like object syntax

XFDF import requires a single completed root element and matching qualified closing tags, checks quoted and separated attributes for duplicate names, and rejects malformed or unknown character references and unsupported declarations such as DTDs

Empty fields and annots containers leave following siblings intact, and unknown extension subtrees are skipped with bounded nesting while respecting comments, processing instructions, and CDATA boundaries

Text values support the five predefined XML entities and decimal or lowercase-x hexadecimal character references for valid Unicode scalars, together with CDATA and intervening comments or processing instructions; this parser does not perform complete XML schema or namespace validation

The FDF parser supports direct and indirect hierarchical field dictionaries, escaped literal strings, hexadecimal strings, PDFDocEncoding, UTF-16 text, name values, arrays, comments, and explicit empty values

XfdfFindAttribute and XfdfFindAttr are convenience lookups for reading attributes off a parsed annotation or its raw name-value pair list

Functions

FunctionDescription
XfdfExportToStreamSerializes fields and annotations to a stream as UTF-8 XFDF and returns the byte count
XfdfExportToFileSerializes fields and annotations to a file as UTF-8 XFDF and returns the byte count
XfdfImportFromStreamParses an XFDF stream into fields, annotations, and file identifiers
XfdfImportFromFileParses an XFDF file into fields, annotations, and file identifiers
FdfExportToStreamSerializes fields to a stream as FDF and returns the byte count
FdfExportToFileSerializes fields to a file as FDF and returns the byte count
FdfImportFromStreamParses an FDF stream into hierarchical fields and the optional source file
FdfImportFromFileParses an FDF file into hierarchical fields and the optional source file
XfdfFindAttributeLooks up a named attribute on a parsed annotation and returns its value
XfdfFindAttrLooks up a named attribute in a name-value pair array

Types

TypeDescription
XFDFStringString type used for XFDF text (UnicodeString on Delphi, WideString on FPC)
TXfdfNameValuePairRecord holding one decoded XML attribute as a Name and Value pair of AnsiString
TXfdfNameValuePairsDynamic array of decoded XML name-value pairs
TXfdfWideStringsDynamic array of XFDF text values
TXfdfFieldRecord describing one form field: Name is the partial field name, Value and HasValue carry the current value, Values collects every parsed value element for multi-value fields, Children nests child fields for hierarchical names, and RichText holds the value-richtext content: its XHTML markup as written, or unescaped plain text when it holds no element. On export, rich text that starts with < is written as markup and anything else is escaped
TXfdfFieldArrayDynamic array of form field records; the shared field tree type used by both XFDF and FDF results
TXfdfAnnotationExportRecord describing one annotation for export, including PageIndex, Subtype, Flags, HasColor and colour pairs, Rectangle, and geometry, plus ContentsText, AuthorText, Subject, ModificationDate, CreationDate, Icon, Opacity, Appearance, HasAppearance, ColorHex, Coords, Action, Destination, HasAction, HasContents, HasDestination, HasInkList, HasInteriorColor, HasLineEndpoints, HasOpacity, HasPopup, HasRichText, HasVertices, InReplyTo, InkGestures, InteriorColorHex, LineEnd, LineStart, Name, PopupOpen, ReplyType, RichText, and Vertices
TXfdfAnnotationExportArrayDynamic array of annotation export descriptors
TXfdfParsedAnnotationRecord describing one annotation parsed from an XFDF document, including PageIndex, ElementName, the raw Attributes name-value pairs, Contents, Action, Destination, and geometry, plus Appearance, HasAppearance, HasAction, HasContents, HasDestination, HasPopup, HasRichText, InkGestures, PopupOpen, RichText, and Vertices
TXfdfParsedAnnotationArrayDynamic array of annotations parsed from an XFDF document
TXfdfExportOptionsRecord carrying SourceFileName, emitted as the source file element, FileIdOriginal and FileIdModified, emitted together as the file identifier element, and NamespaceAttributes, emitted as additional namespace declarations on the root element
TXfdfImportResultResult record bundling the parsed Fields tree, the parsed Annotations, the SourceFile reference, the FileIdOriginal and FileIdModified identifiers, and the NamespaceAttributes captured from the root element
TFdfImportResultResult record bundling the parsed FDF Fields tree and the optional SourceFile target read from the /F entry

Remarks

See Also

TPdf.ExportXFDF, TPdf.ImportXFDF, TPdf.ExportFDF, TPdf.ImportFDF