|
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);
Mô tả
Các phương thức này kiểm tra và cập nhật các trường AcroForm đã tồn tại trong
một PDF được tải bằng LoadFromFile hoặc
BeginIncrementalUpdate. Chúng hỗ trợ trường văn bản
(/FT /Tx), trường nút (/FT /Btn), trường lựa chọn
(/FT /Ch), trường chữ ký
(/FT /Sig) và cả các kiểu trường không xác định
GetLoadedAcroForm trả về từ điển /AcroForm đã tải và đã phân giải cho những người gọi cần kiểm tra trực tiếp từ điển trước khi dùng các phương thức trường ở mức cao hơn
HasFormFields cho biết PDF đã tải hoặc tài liệu đang soạn có trường AcroForm hay không. FormFieldExists kiểm tra cây trường đã tải hoặc danh sách trường đang tạo theo tên trường mà không ném lỗi khi trường không tồn tại
GetFormFieldDescription đọc tên thay thế /TU của trường đã tải, thường được các trình xem PDF dùng làm tooltip của trường. Hàm trả về chuỗi rỗng khi trường không có mô tả
GetFormFieldOptionCount và
GetFormFieldOptionValue đọc mảng /Opt
trên các trường lựa chọn đã tải. Các mục chuỗi đơn được trả về trực tiếp;
các mảng tùy chọn hai phần tử trả về giá trị export đầu tiên
IsFormFieldReadOnly đọc bit 1 của cờ /Ff của trường đã tải. RenameFormField cập nhật tên cục bộ /T của trường đã tải và từ chối các tên đầy đủ bị trùng trong cùng cây biểu mẫu đã tải
RemoveFormField xóa một trường biểu mẫu đã tải khỏi
cây trường AcroForm và gỡ các chú thích widget tương ứng khỏi
các trang của chúng. FlattenFormFields vẽ các giá trị đang hiển thị
của các trường đã tải hoặc đang tạo vào nội dung tĩnh của trang, rồi
xóa mục catalog AcroForm và các chú thích widget để PDF đã lưu
không còn lộ các trường tương tác. Hàm trả về số trường đã được làm phẳng,
hoặc 0 khi không có trường biểu mẫu nào
Dùng SaveLoadedDocument để ghi một bản sao đã lưu đầy đủ của
đồ thị đối tượng đã tải sau khi chỉnh trực tiếp các trường. Với luồng
chỉ nối thêm như PDF đã ký, hãy tải bằng BeginIncrementalUpdate, sửa
các trường rồi gọi 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
|