|
THotPDF Loaded Form Field Methods
構文
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);
説明
これらのメソッドは、LoadFromFile または BeginIncrementalUpdate で読み込まれた PDF にすでに存在する AcroForm フィールドを検査および更新します。text field (/FT /Tx)、button field (/FT /Btn)、choice field (/FT /Ch)、signature field (/FT /Sig)、unknown field type をサポートします
GetLoadedAcroForm は上位のフィールドメソッドを使う前に直接調査できる、解決済みの読み込み済み /AcroForm 辞書を返します
GetFormFieldDescription は読み込み済みフィールドの /TU alternate field name を読み取ります。これは PDF ビューアーでフィールド tooltip としてよく使用されます。フィールドに説明がない場合は空文字列を返します
GetFormFieldOptionCount と GetFormFieldOptionValue は、読み込み済み choice field の /Opt 配列を読み取ります。単純な文字列 entry はそのまま返され、2 要素の option array では最初の export value が返されます
IsFormFieldReadOnly は読み込み済みフィールドの /Ff フラグの bit 1 を読み取ります。RenameFormField は読み込み済みフィールドのローカル /T 名を更新し、同じ読み込み済み form tree 内で完全修飾名が重複する場合は拒否します
RemoveFormField は読み込み済み form field を AcroForm field tree から削除し、対応する widget annotation を各ページから削除します。FlattenFormFields は読み込み済みフィールドの現在の表示値を静的ページコンテンツへ描画し、その後 AcroForm catalog entry と widget annotation を削除するため、保存後の PDF は対話型フィールドを公開しなくなります
直接フィールド編集後に、読み込み済み object graph の完全保存コピーを書き出すには SaveLoadedDocument を使用します。署名済み PDF のような append-only ワークフローでは、BeginIncrementalUpdate で読み込み、フィールドを編集してから SaveIncrementalUpdate を呼び出します
例
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');
関連項目
|