|
THotPDF Loaded Form Field Methods
Syntax
function GetFormFieldCount: Integer;
function GetFormFieldName(FieldIndex: Integer): AnsiString;
function GetFormFieldValue(FieldIndex: Integer): AnsiString; overload;
function GetFormFieldValue(const FieldName: AnsiString): AnsiString; overload;
function GetFormFieldType(FieldIndex: Integer): THPDFLoadedFormFieldType; overload;
function GetFormFieldType(const FieldName: AnsiString): THPDFLoadedFormFieldType; overload;
function GetFormFieldDescription(FieldIndex: Integer): AnsiString; overload;
function GetFormFieldDescription(const FieldName: AnsiString): AnsiString; overload;
function GetFormFieldOptionCount(FieldIndex: Integer): Integer; overload;
function GetFormFieldOptionCount(const FieldName: AnsiString): Integer; overload;
function GetFormFieldOptionValue(FieldIndex, OptionIndex: Integer): AnsiString; overload;
function GetFormFieldOptionValue(const FieldName: AnsiString; OptionIndex: Integer): AnsiString; overload;
function IsFormFieldReadOnly(FieldIndex: Integer): Boolean; overload;
function IsFormFieldReadOnly(const FieldName: AnsiString): Boolean; overload;
procedure SetFormFieldValue(FieldIndex: Integer; const Value: AnsiString); overload;
procedure SetFormFieldValue(const FieldName, Value: AnsiString); overload;
procedure SetFormFieldReadOnly(FieldIndex: Integer; ReadOnly: Boolean); overload;
procedure SetFormFieldReadOnly(const FieldName: AnsiString; ReadOnly: Boolean); overload;
procedure RenameFormField(FieldIndex: Integer; const NewName: AnsiString); overload;
procedure RenameFormField(const FieldName, NewName: AnsiString); overload;
procedure RemoveFormField(FieldIndex: Integer); overload;
procedure RemoveFormField(const FieldName: AnsiString); overload;
procedure FlattenFormFields;
procedure SaveLoadedDocument(const TargetFile: TFileName);
Description
These methods inspect and update AcroForm fields that already exist in
a PDF loaded with LoadFromFile or
BeginIncrementalUpdate. They support text fields
(/FT /Tx), button fields (/FT /Btn), choice
fields (/FT /Ch), signature fields
(/FT /Sig), and unknown field types
GetLoadedAcroForm returns the resolved loaded /AcroForm dictionary for direct inspection before using the higher-level field methods
GetFormFieldDescription reads the loaded field's
/TU alternate field name, commonly used by PDF viewers as
the field tooltip. It returns an empty string when the field has no
description
GetFormFieldOptionCount and
GetFormFieldOptionValue read the
GetFormFieldOptionCount and
GetFormFieldOptionValue read the /Opt array
on loaded choice fields. Simple string entries are returned directly;
two-element option arrays return the first export value
IsFormFieldReadOnly reads bit 1 of the loaded field's
/Ff flag. RenameFormField updates the loaded
field's local /T name and rejects duplicate fully qualified
names in the same loaded form tree
RemoveFormField deletes a loaded form field from the
AcroForm field tree and removes the matching widget annotations from
their pages.
RecalculateLoadedFormFields visits the loaded
/AcroForm /CO array in document order and evaluates the
bounded AFSimple_Calculate operations SUM,
AVG, PRD, MIN, and
MAX. Updated values receive regenerated appearances
RemoveFormField deletes a loaded form field from the
AcroForm field tree and removes the matching widget annotations from
its pages. FlattenLoadedFormFields paints only the named
fields into static content on their owning pages, removes their widget
annotations, and preserves untouched fields and pages. An empty name
array selects every field. The default permission gate refuses any
structural change prohibited by DocMDP or FieldMDP signatures
FlattenFormFields paints the current visible
values of loaded fields into static page content, then removes the
AcroForm catalog entry and widget annotations so the saved PDF no
longer exposes interactive fields
Use SaveLoadedDocument to write a fully saved copy of the
loaded object graph after direct field edits. For append-only workflows
such as signed PDFs, load with BeginIncrementalUpdate, edit
fields, and then call SaveIncrementalUpdate
Example
PDF.LoadFromFile('InputForm.pdf');
for I := 0 to PDF.GetFormFieldCount - 1 do
Writeln(PDF.GetFormFieldName(I), ' = ', PDF.GetFormFieldValue(I));
for I := 0 to PDF.GetFormFieldOptionCount('Plan') - 1 do
Writeln('Plan option ', I, ': ', PDF.GetFormFieldOptionValue('Plan', I));
Writeln('Customer description: ', PDF.GetFormFieldDescription('CustomerName'));
PDF.SetFormFieldValue('CustomerName', 'Bob');
PDF.SetFormFieldReadOnly('CustomerName', True);
PDF.RenameFormField('CustomerName', 'ClientName');
PDF.RemoveFormField('Approved');
PDF.SaveLoadedDocument('UpdatedForm.pdf');
PDF.LoadFromFile('UpdatedForm.pdf');
PDF.FlattenFormFields;
PDF.SaveLoadedDocument('FlattenedForm.pdf');
PDF.BeginIncrementalUpdate('SignedForm.pdf');
FlattenedCount := PDF.FlattenLoadedFormFields(['CalculatedTotal']);
PDF.SaveIncrementalUpdate('SignedForm-flattened.pdf');
See Also
|