AcroForm Support

개요

HotPDF v2.5.0부터 라이브러리는 PDF 1.7 ISO 32000-1 section 12.7에 따른 interactive forms(AcroForm)를 생성할 수 있습니다. 각 form field는 field dictionary와 병합된 Widget annotation으로 생성되고 문서에 자동 등록되므로, EndDoc에서 문서가 완료될 때 전역 /AcroForm 항목이 Catalog에 추가됩니다

지원되는 field type

  • Text fields (/FT /Tx) via THPDFPage.AddTextField. Supports single-line, multi-line, password, comb, file-select, rich-text, scroll and spell-check options through THPDFFormFieldFlags.
  • Check boxes (/FT /Btn, no Pushbutton/Radio bits) via THPDFPage.AddCheckBox with a configurable export value name and initial checked state.
  • THPDFPage.AddRadioButton을 통한 radio button(/FT /Btn /Ff Radio)을 지원합니다. 같은 group name으로 여러 번 호출하면 12.7.4.2 요구사항과 정확히 맞게 /Kids array가 있는 공유 parent field 아래로 병합됩니다
  • Combo boxes (/FT /Ch /Ff Combo) via THPDFPage.AddComboBox. Pass an open array of options.
  • List boxes (/FT /Ch) via THPDFPage.AddListBox. ffMultiSelect enables multi-select.
  • THPDFPage.AddPushButton을 통해 선택적 caption(/MK /CA)이 있는 push button(/FT /Btn /Ff Pushbutton)을 만들 수 있습니다. HotPDF v2.31.0부터 THPDFPage.AddPushButtonWithAction은 widget에 PDF action dictionary를 붙여 버튼 클릭 시 /SubmitForm(field value를 URL로 게시, PDF 1.2 12.7.5.2), /ResetForm(PDF 1.2 12.7.5.3), /JavaScript(JS snippet 실행, PDF 1.3 12.6.4.16), /URI(시스템 브라우저에서 URL 열기, PDF 1.1 12.6.4.7)를 실행합니다
  • HotPDF v2.12.0부터 THPDFPage.AddSignatureField를 통한 signature placeholder field(/FT /Sig)를 지원합니다. 하나 이상의 signature field가 있으면 AcroForm dictionary에 /SigFlags 3(SignaturesExist + AppendOnly)이 자동으로 추가됩니다. 이 field는 unsigned 상태로 남기므로 외부 도구(Adobe Acrobat, Foxit, 전용 CMS / PKCS#7 signing libraries)가 파일 저장 후 실제 cryptographic signature를 첨부할 수 있습니다
  • HotPDF v2.23.0부터 THPDFPage.AddSignedSignatureField + THotPDF.PreparePDFForSigning + THotPDF.InsertSignatureHex를 통한 in-place signing workflow를 지원합니다. 첫 호출은 /ByteRange/Contents placeholder가 있는 /V signature dictionary를 예약합니다. 문서를 저장한 뒤 host application은 PreparePDFForSigning을 호출해 /ByteRange를 패치하고 hash할 file range를 확인합니다. 이후 외부에서 CMS / PKCS#7 detached signature(Windows CryptoAPI, OpenSSL, 전용 signing libraries)를 만든 다음 InsertSignatureHex를 호출해 파일의 다른 byte를 건드리지 않고 placeholder에 signature hex를 넣습니다

Loaded form-field inspection and updates

HotPDF v2.121.9부터 application은 THotPDF.LoadFromFile로 기존 AcroForm PDF를 로드하고, field를 열거하고, 이름, type, value를 읽고, field value를 변경하고, read-only flag를 전환한 뒤 THotPDF.SaveLoadedDocument로 로드된 object graph를 저장할 수 있습니다. 이 경로는 이미 로드된 문서에 대한 영구 편집용입니다. 로드된 field-value 변경만 저장하려고 BeginDoc / EndDoc를 호출하지 마십시오

Field helper는 GetFormFieldCount, GetFormFieldName, GetFormFieldType, GetFormFieldValue, SetFormFieldValue, SetFormFieldReadOnly입니다. Field lookup은 zero-based field index 또는 fully qualified field name을 받습니다. 반환되는 THPDFLoadedFormFieldType 값은 lfftText, lfftButton, lfftChoice, lfftSignature, lfftUnknown입니다

Loaded-field Pascal example

HPDF.LoadFromFile('InputForm.pdf');
for I := 0 to HPDF.GetFormFieldCount - 1 do
  Writeln(HPDF.GetFormFieldName(I), ' = ', HPDF.GetFormFieldValue(I));

HPDF.SetFormFieldValue('CustomerName', 'Bob');
HPDF.SetFormFieldValue('Plan', 'Premium');
HPDF.SetFormFieldReadOnly('CustomerName', True);
HPDF.SaveLoadedDocument('UpdatedForm.pdf');

Field additional actions

Wrapper AttachFieldKeyStrokeAction, AttachFieldFormatAction, AttachFieldValidateAction, AttachFieldCalculateAction은 PDF /K, /F, /V, /C trigger에 대해 field의 /AA dictionary에 JavaScript를 첨부합니다. keystroke filtering, display formatting, validation, calculated-field update가 button action이 아니라 field와 함께 있어야 할 때 field 생성 또는 로드 후 사용하십시오

Appearance generation

기본적으로 생성되는 /AcroForm dictionary는 /NeedAppearances true를 설정하고 appearance-stream rendering을 소비자 viewer(Adobe Reader, Foxit, Chrome, browsers, Apple Preview)에 위임합니다. Field를 추가하기 전에 THotPDF.AutoFormAppearances를 true로 설정하면 HotPDF는 모든 text field, push button, choice(combo / list), 모든 checkbox / radio kid의 Yes / Off 상태에 대해 /AP /N Form XObjects(PDF 1.7 8.10)를 미리 빌드합니다. 그러면 AcroForm dictionary는 /NeedAppearances false와 standard 14 base fonts(Helv Helvetica, ZaDb ZapfDingbats)를 참조하는 /DR default resources entry를 포함하므로, /NeedAppearances를 무시하는 renderer도 field content를 올바르게 그립니다. HotPDF v2.28.0부터 사용할 수 있습니다

Field flag reference (THPDFFormFieldFlags)

  • ffReadOnly, ffRequired, ffNoExport — common Table 227 flags applicable to every field type.
  • ffMultiline, ffPassword, ffFileSelect, ffDoNotSpellCheck, ffDoNotScroll, ffComb, ffRichText — Tx-specific (Table 228).
  • ffEdit, ffSort, ffMultiSelect, ffDoNotSpellCheck, ffCommitOnSelChange — Ch-specific (Table 230).

Pascal example

HPDF.BeginDoc;
HPDF.AddPage;
HPDF.CurrentPage.AddTextField('Name', '', Rect(50, 100, 250, 120));
HPDF.CurrentPage.AddCheckBox('Agree', 'Yes', Rect(50, 130, 70, 145), True);
HPDF.CurrentPage.AddRadioButton('Color', 'Red',   Rect(50, 160, 70, 175), True);
HPDF.CurrentPage.AddRadioButton('Color', 'Green', Rect(80, 160, 100, 175));
HPDF.CurrentPage.AddRadioButton('Color', 'Blue',  Rect(110, 160, 130, 175));
HPDF.CurrentPage.AddComboBox('Country', 'CN',
                             ['CN', 'US', 'JP'], Rect(50, 190, 250, 210));
HPDF.EndDoc;

Limitations

  • AutoFormAppearances generator는 현재 ASCII / WinAnsi-encodable 값만 배치합니다. /V에 multi-byte(UTF-8) text가 포함된 field의 경우 host viewer가 appearance를 다시 생성할 때까지 저장된 /AP는 빈 사각형으로 렌더링됩니다
  • Down(/D) 및 rollover(/R) sub-state는 생성되지 않으며 normal(/N) state만 생성됩니다
  • Field name uniqueness is the caller's responsibility; HotPDF does not enforce it.

See Also