THotPDF.AddXFAPacket / ClearXFAPackets / XFAPacketCount

THotPDF XFA forms container (v2.119.51)

 

RegisterAcroFormFont  AcroForm Support

Реєструє named XFA (XML Forms Architecture) packet для emission всередині entry AcroForm /XFA документа PDF 1.7 §12.7.6 + §12.7.8 дозволяє AcroForm містити /XFA array поруч зі static /Fields array (або замість нього), що вмикає hybrid AcroForm + XFA workflows або pure dynamic XFA forms

 

Delphi syntax:

procedure AddXFAPacket(const PacketName: AnsiString; const XMLBytes: TBytes);

procedure ClearXFAPackets;

function XFAPacketCount: Integer;

 

Опис

Кожен call AddXFAPacket реєструє один named packet Типові names (за XFA 3.3 specification і PDF 1.7 §12.7.8 Table 234):

 

template - form layout + scripts (the largest packet in most XFA documents).

datasets - data binding (the XML payload the template renders against).

config - viewer configuration.

connectionSet - external data connections.

localeSet - locale-specific formatting rules.

stylesheet - XSLT or CSS styling.

xfdf - XFDF form data overlay.

xmpmeta - XMP metadata.

signature - signature-related XFA data.

sourceSet - source-side data definitions.

 

Під час EndDoc кожен registered packet стає indirect FlateDecode-compressed stream object, а AcroForm /XFA array чергує packet-name PDF strings зі stream references у registration order, тому layout є byte-deterministic ClearXFAPackets видаляє всі registered packets (корисно для reuse THotPDF instance across multiple documents) XFAPacketCount повертає current count

 

Container-level support only

HotPDF не parse XFA XML, не implement XFA dynamic-layout engine, не execute FormCalc або JavaScript усередині XFA template і не validate template structure Caller сам authors XFA XML (зазвичай через Adobe LiveCycle Designer або вручну за XFA 3.3 specification), а HotPDF emit bytes verbatim

 

Consumer readers з XFA engine (старі Acrobat / Reader, FormsCentral, деякі kiosk products) render form; readers без XFA engine (Adobe Reader DC з 2017 onward, most open-source readers) показують fallback AcroForm fields, якщо document є hybrid AcroForm + XFA workflow

 

PDF/A and PDF/X compliance gates

ISO 19005-1 §6.4.2 / ISO 19005-2 §6.4.2 / ISO 19005-3 §6.4.2 явно disallow XFA forms (dynamic-layout engine не є deterministically archivable) ISO 15930 prepress workflows повністю reject interactive forms AddXFAPacket негайно raises під будь-яким non-empty PDFACompliance або PDFXCompliance з відповідним spec reference Duplicate packet names raise Empty PacketName або empty XMLBytes raise RequirePDFVersion(pdf15) auto-bumps document version

 

AcroForm dictionary emission

AcroForm dict emitиться, коли /Fields має принаймні один entry або зареєстровано принаймні один XFA packet Pre-v2.119.51 callers, що не register packets, зберігають byte-identical /AcroForm output

 

Typical workflow (pure XFA dynamic form)

 

PDF.BeginDoc;

TemplateBytes := TFile.ReadAllBytes('form-template.xml');

DataBytes     := TFile.ReadAllBytes('form-data.xml');

PDF.AddXFAPacket('xdp:xdp', BytesOf('<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">'));

PDF.AddXFAPacket('template', TemplateBytes);

PDF.AddXFAPacket('datasets', DataBytes);

PDF.AddXFASignaturePacket(SigBytes); { caller-generated XAdES }

PDF.AddXFAPacket('/xdp:xdp', BytesOf('</xdp:xdp>'));

PDF.EndDoc;

 

XDP wrapper, single-stream, dynamic, and signed XFA

The array /XFA form must open and close with xdp:xdp wrapper packets, as the example now shows (ISO 32000-1 §12.7.8). Related XFA APIs: SetXFADocument writes the whole XFA/XDP document as a single /XFA stream, mutually exclusive with AddXFAPacket; XFANeedsRendering sets the Catalog /NeedsRendering flag (ISO 32000-1 §7.7.2) so a viewer regenerates a dynamic XFA form on first open; AddXFASignaturePacket embeds a caller-generated XAdES / XML-DSig signature as the signature packet. HotPDF never generates or parses the signature - the caller produces it with an XML cryptographic library over the XFA datasets.

 

XFA-to-AcroForm flattening

ApplyXFAAsAcroForm maps caller-supplied XDP/XFA bytes на current page як native AcroForm widgets і simple page graphics FlattenLoadedXFA виконує таке саме conversion для loaded PDF, який already carries embedded /XFA packet Передайте Editable=False, щоб generated widgets стали read-only, і inspect XFAFlattenWarnings для elements, які не вдалося map

 

See also: AcroForm Support, THotPDF.RegisterAcroFormFont, THPDFPage.AddTextField