|
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 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);
Description
이 메서드들은 LoadFromFile 또는 BeginIncrementalUpdate로 로드한 PDF에 이미 있는 AcroForm 필드를 조회하고 수정합니다. 텍스트 필드(/FT /Tx), 버튼 필드(/FT /Btn), 선택 필드(/FT /Ch), 서명 필드(/FT /Sig), 그리고 알 수 없는 필드 타입을 지원합니다
GetLoadedAcroForm은 상위 수준 필드 메서드를 쓰기 전에 사전을 직접 살펴봐야 하는 호출자를 위해, 해석(resolve)된 로드 문서의 /AcroForm 사전을 반환합니다
HasFormFields는 로드된 PDF 또는 현재 작성 중인 문서에 AcroForm 필드가 있는지 알려 줍니다. FormFieldExists는 로드된 필드 트리 또는 작성 중인 필드 목록에서 필드 이름으로 존재 여부를 확인하며, 필드가 없어도 예외를 발생시키지 않습니다
GetFormFieldDescription은 로드된 필드의 /TU 대체 필드 이름을 읽습니다. PDF 뷰어는 보통 이 값을 필드 툴팁으로 사용합니다. 필드에 설명이 없으면 빈 문자열을 반환합니다
GetFormFieldOptionCount와 GetFormFieldOptionValue는 로드된 선택 필드의 /Opt 배열을 읽습니다. 단순 문자열 항목은 그대로 반환하고, 요소가 두 개인 옵션 배열은 첫 번째 export 값을 반환합니다
IsFormFieldReadOnly는 로드된 필드의 /Ff 플래그 중 비트 1을 읽습니다. RenameFormField는 로드된 필드의 로컬 /T 이름을 갱신하며, 같은 로드된 폼 트리 안에서 fully qualified name이 중복되면 거부합니다
로드된 폼 관계 캐시는 한 번의 지연 선형 빌드로 필드, qualified name, 위젯, 주석, 페이지를 양방향으로 매핑합니다. 상위 수준의 변경 메서드는 이 캐시를 자동으로 유지하거나 무효화합니다. raw 객체 API로 관계가 바뀌는 편집을 했다면 그 뒤에 InvalidateLoadedFormRelationshipCache를 호출하세요
RecalculateLoadedFormFields는 로드된 /AcroForm /CO 배열을 문서 순서대로 훑으면서 bounded AFSimple_Calculate 연산인 SUM, AVG, PRD, MIN, MAX를 계산합니다. 값이 갱신된 필드는 appearance가 다시 생성됩니다
RemoveFormField는 로드된 폼 필드를 AcroForm 필드 트리에서 삭제하고, 해당 페이지에서 대응하는 위젯 주석도 제거합니다. FlattenLoadedFormFields는 지정한 이름의 필드만 소유 페이지의 정적 콘텐츠로 그려 넣고, 그 위젯 주석을 제거하며, 건드리지 않은 필드와 페이지는 그대로 둡니다. 이름 배열이 비어 있으면 모든 필드가 대상입니다. 기본 권한 게이트는 DocMDP 또는 FieldMDP 서명이 금지하는 구조 변경을 모두 거부합니다
FlattenFormFields는 전체 필드 대상의 편의 계약을 그대로 유지하면서, 로드된 문서는 서명을 인식하는 동일한 페이지 단위 경로에 위임합니다. flatten한 필드 수를 반환하며, 일치하는 폼 필드가 없으면 0을 반환합니다
필드를 직접 수정한 뒤 로드된 객체 그래프 전체를 새로 저장하려면 SaveLoadedDocument를 사용하세요. 서명된 PDF처럼 append-only 워크플로가 필요하면 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.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');
See Also
|