THotPDF Loaded Form Field Methods

構文

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 GetLoadedFormFieldWidgetPageIndex(FieldIndex,
  WidgetIndex: Integer): Integer;
function GetLoadedFormFieldIndexForAnnotation(PageIndex,
  AnnotationIndex: Integer; out WidgetIndex: Integer): Integer;
procedure InvalidateLoadedFormRelationshipCache;
function GetLoadedFormRelationshipCacheStatistics(
  out Statistics: THPDFFormRelationshipCacheStatistics): Boolean;
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 RecalculateLoadedFormFields: Integer;
function FlattenLoadedFormFields(const FieldNames: array of AnsiString;
  EnforceSignaturePermissions: Boolean = True): Integer;
function FlattenFormFields: Integer;
procedure SaveLoadedDocument(const TargetFile: TFileName);

説明

これらのメソッドは、LoadFromFile や BeginIncrementalUpdate で読み込んだ PDF にすでに存在する AcroForm フィールドを検査・更新します。テキストフィールド(/FT /Tx)、ボタンフィールド(/FT /Btn)、choice フィールド(/FT /Ch)、署名フィールド(/FT /Sig)、未知のフィールドタイプに対応します

GetLoadedAcroForm は、解決済みのロード済み /AcroForm 辞書を返します。高レベルのフィールドメソッドを使う前に辞書を直接検査したい呼び出し側向けです

HasFormFields は、ロード済み PDF や進行中のドキュメントが AcroForm フィールドを持つかどうかを報告します。FormFieldExists は、フィールドが存在しなくても例外を投げずに、フィールド名でロード済みフィールドツリーまたはオーサリングフィールドリストをチェックします

GetFormFieldDescription は、ロード済みフィールドの /TU 代替フィールド名を読み取ります。PDF ビューアがフィールドのツールチップとして使うものです。フィールドに説明がない場合は空文字列を返します

GetFormFieldOptionCount と GetFormFieldOptionValue は、ロード済み choice フィールドの /Opt 配列を読み取ります。単純な文字列エントリはそのまま返り、2 要素のオプション配列は最初のエクスポート値を返します

IsFormFieldReadOnly は、ロード済みフィールドの /Ff フラグのビット 1 を読み取ります。RenameFormField はロード済みフィールドのローカルな /T 名を更新し、同じロード済みフォームツリー内の重複する完全修飾名を拒否します

ロード済みフォームのリレーションシップキャッシュは、1 回の遅延線形構築の後、フィールド、完全修飾名、ウィジェット、注釈、ページを双方向にマップします。高レベルの変更メソッドはこれを自動的に維持 / 無効化します。raw オブジェクト API でリレーションシップを変える編集をした後は、InvalidateLoadedFormRelationshipCache を呼び出してください

RecalculateLoadedFormFields は、ロード済みの /AcroForm /CO 配列をドキュメント順にたどり、境界付きの AFSimple_Calculate 演算 SUM、AVG、PRD、MIN、MAX を評価します。更新された値は再生成された外観を受け取ります

RemoveFormField は、ロード済みフォームフィールドを AcroForm フィールドツリーから削除し、対応するウィジェット注釈をそのページから取り除きます。FlattenLoadedFormFields は、名前を指定されたフィールドだけを所有ページの静的コンテンツに描き込み、ウィジェット注釈を取り除き、触れていないフィールドとページを保持します。空の名前配列はすべてのフィールドを選択します。既定の権限ゲートは、DocMDP / FieldMDP 署名が禁止する構造変更を一切受け付けません

FlattenFormFields は全フィールド一括の利便性契約を保持しつつ、ロード済みドキュメントを同じ署名認識のページローカルパスへ委譲します。フラット化されたフィールド数を返し、一致するフォームフィールドがない場合は 0 を返します

フィールドを直接編集した後、SaveLoadedDocument でロード済みオブジェクトグラフの完全保存コピーを書き出せます。署名済み PDF などの追記型ワークフローでは、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.RecalculateLoadedFormFields;
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');
PDF.BeginIncrementalUpdate('SignedForm.pdf');
FlattenedCount := PDF.FlattenLoadedFormFields(['CalculatedTotal']);
PDF.SaveIncrementalUpdate('SignedForm-flattened.pdf');

関連項目