|
THotPDF Loaded Form Field Methods
Syntax
function GetLoadedAcroForm: THPDFDictionaryObject;
function HasFormFields: Boolean;
function FormFieldExists(const FieldName: AnsiString): Boolean;
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;
function FlattenFormFields: Integer;
procedure SaveLoadedDocument(const TargetFile: TFileName);
Опис
Ці methods переглядають і оновлюють AcroForm fields, які вже існують у PDF, завантаженому через LoadFromFile або BeginIncrementalUpdate Вони підтримують text fields (/FT /Tx), button fields (/FT /Btn), choice fields (/FT /Ch), signature fields (/FT /Sig) і unknown field types
GetLoadedAcroForm повертає resolved loaded /AcroForm dictionary для callers, яким потрібна direct dictionary inspection перед використанням higher-level field methods
HasFormFields повідомляє, чи має loaded PDF або поточний in-progress document AcroForm fields FormFieldExists перевіряє loaded field tree або authoring field list за field name без raise, коли field відсутній
GetFormFieldDescription читає /TU alternate field name завантаженого field, який PDF viewers часто використовують як tooltip field Повертає empty string, коли field не має description
GetFormFieldOptionCount і GetFormFieldOptionValue читають /Opt array на loaded choice fields Simple string entries повертаються напряму; two-element option arrays повертають перше export value
IsFormFieldReadOnly читає bit 1 flag /Ff завантаженого field RenameFormField оновлює local /T name завантаженого field і відхиляє duplicate fully qualified names у тому самому loaded form tree
RemoveFormField видаляє loaded form field з AcroForm field tree і прибирає matching widget annotations зі сторінок FlattenFormFields малює поточні visible values loaded або in-progress fields у static page content, потім видаляє AcroForm catalog entry і widget annotations, щоб saved PDF більше не expose interactive fields Повертає кількість flattened fields або zero, коли form fields не було
Використовуйте SaveLoadedDocument, щоб записати повністю saved copy loaded object graph після direct field edits Для append-only workflows, таких як signed PDFs, завантажуйте через BeginIncrementalUpdate, редагуйте fields, а потім викликайте 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');
if PDF.HasFormFields then
Writeln('Plan exists: ', PDF.FormFieldExists('Plan'));
FlattenedCount := PDF.FlattenFormFields;
PDF.SaveLoadedDocument('FlattenedForm.pdf');
See Also
|