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);

설명

이 method들은 LoadFromFile 또는 BeginIncrementalUpdate로 로드한 PDF에 이미 존재하는 AcroForm field를 inspect하고 update합니다. Text field(/FT /Tx), button field(/FT /Btn), choice field(/FT /Ch), signature field(/FT /Sig), unknown field type을 지원합니다

GetLoadedAcroForm은 higher-level field method를 사용하기 전에 직접 dictionary inspection이 필요한 호출자를 위해 resolved loaded /AcroForm dictionary를 반환합니다

HasFormFields는 loaded PDF 또는 현재 in-progress document에 AcroForm field가 있는지 보고합니다. FormFieldExists는 field가 없을 때 raise하지 않고 field name으로 loaded field tree 또는 authoring field list를 검사합니다

GetFormFieldDescription은 PDF viewer가 흔히 field tooltip으로 사용하는 loaded field의 /TU alternate field name을 읽습니다. Field에 description이 없으면 빈 string을 반환합니다

GetFormFieldOptionCountGetFormFieldOptionValue는 loaded choice field의 /Opt array를 읽습니다. 단순 string entry는 직접 반환되고, two-element option array는 첫 번째 export value를 반환합니다

IsFormFieldReadOnly는 loaded field의 /Ff flag 중 bit 1을 읽습니다. RenameFormField는 loaded field의 local /T name을 update하고 같은 loaded form tree 안의 duplicate fully qualified name을 거부합니다

RemoveFormField는 AcroForm field tree에서 loaded form field를 삭제하고 해당 page에서 matching widget annotation을 제거합니다. FlattenFormFields는 loaded 또는 in-progress field의 현재 visible value를 static page content에 그린 뒤 AcroForm catalog entry와 widget annotation을 제거하여 저장된 PDF가 더 이상 interactive field를 노출하지 않게 합니다. Flatten된 field 수를 반환하며 form field가 없으면 zero를 반환합니다

직접 field edit 후 loaded object graph의 fully saved copy를 쓰려면 SaveLoadedDocument를 사용하십시오. Signed PDF 같은 append-only workflow에서는 BeginIncrementalUpdate로 로드하고 field를 edit한 뒤 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