|
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);
說明
這些方法會檢查並更新已透過 LoadFromFile 或 BeginIncrementalUpdate 載入的 PDF 中既有的 AcroForm 欄位。它們支援文字欄位 (/FT /Tx)、按鈕欄位 (/FT /Btn)、選擇欄位 (/FT /Ch)、簽章欄位 (/FT /Sig),以及未知欄位型別
GetLoadedAcroForm 會傳回已解析的載入 /AcroForm 字典,供需要在使用高階欄位方法前直接檢查字典的呼叫端使用
HasFormFields 會回報已載入 PDF 或目前建立中的檔案是否具有 AcroForm 欄位。FormFieldExists 會依欄位名稱檢查載入的欄位樹或建立中的欄位清單,欄位不存在時不會擲回例外
GetFormFieldDescription 會讀取載入欄位的 /TU 替代欄位名稱,PDF 檢視器通常會將其作為欄位工具提示。欄位沒有描述時會傳回空字串
GetFormFieldOptionCount 與 GetFormFieldOptionValue 會讀取載入選擇欄位上的 /Opt 陣列。簡單字串項目會直接傳回;雙元素選項陣列會傳回第一個匯出值
IsFormFieldReadOnly 會讀取載入欄位 /Ff 旗標的 bit 1。RenameFormField 會更新載入欄位的本機 /T 名稱,並拒絕同一載入表單樹中的重複完整限定名稱
RemoveFormField 會從 AcroForm 欄位樹刪除載入的表單欄位,並從其頁面移除對應的 widget 註解。
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 會將已載入或建立中欄位的目前可見值繪製為靜態頁面內容,接著移除 AcroForm catalog 項目與 widget 註解,使儲存後的 PDF 不再暴露互動式欄位。它會傳回已扁平化的欄位數量;若沒有表單欄位則傳回零
直接編輯欄位後,請使用 SaveLoadedDocument 寫出載入物件圖的完整儲存副本。對於已簽章 PDF 這類僅附加工作流程,請使用 BeginIncrementalUpdate 載入、編輯欄位,然後呼叫 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');
PDF.BeginIncrementalUpdate('SignedForm.pdf');
FlattenedCount := PDF.FlattenLoadedFormFields(['CalculatedTotal']);
PDF.SaveIncrementalUpdate('SignedForm-flattened.pdf');
請參閱
|