|
將 PDF 1.5+ AcroForm rich-text text widget (ISO 32000-1 12.7.4.3 + Annex L) 加到目前頁面。此 widget 會帶有不解析 rich text 的 reader 所使用的標準 /V + /DV plain-text fallback,另外也包含 Acrobat 與 Foxit 可直接用來轉譯樣式文字的新 /RV rich-text XHTML body 與 /DS default style entries。/Ff RichText bit (26) 會自動 OR 進去
Delphi 語法:
procedure AddRichTextField(const FieldName, InitialValue: AnsiString; const RichValue, DefaultStyle: AnsiString; Rectangle: TRect; MaxLen: Integer = 0; Flags: THPDFFormFieldFlags = []);
C++ 語法:
void AddRichTextField(const AnsiString& FieldName, const AnsiString& InitialValue, const AnsiString& RichValue, const AnsiString& DefaultStyle, const TRect& Rectangle, int MaxLen = 0, THPDFFormFieldFlags Flags = THPDFFormFieldFlags());
說明
InitialValue - 寫入 /V 與 /DV 的 plain-text PDF text string。不解析 /RV 的 readers 會 fallback 到此值進行顯示/V 與 /DV、RichValue 對應 /RV,DefaultStyle 對應 /DS。InitialValue、RichValue 與 DefaultStyle 會自動偵測多位元組內容,必要時切換為 UTF-16BE 十六進位字串編碼(與既有 AddTextField
Rich-text 轉譯會在 reader 中發生:Acrobat / Foxit / Edge / Chrome PDF viewer 都會在 RichText bit 啟用時解析 /RV,並從系統取得 Unicode font fallbacks,因此 CJK、Cyrillic、Arabic 與 accented Latin 內容可正確顯示,而不需要 HotPDF 將 CID font 嵌入 /DR Resources。對於 HotPDF 自身的 AutoFormAppearances 路徑,multi-byte text 的 placeholder empty-AP 分支仍保留(v2.56.0+ task);支援 rich text 的 readers 會忽略該 AP,並直接從 /RV 轉譯
FieldName - PDF form field 的 /T partial name(在其 parent 內必須唯一)。接受空格與非 ASCII bytes;非 ASCII 會讓輸出的 /T string 使用 UTF-16BE encoding
InitialValue - 寫入 /V 與 /DV 的 plain-text PDF text string。不解析 /RV 的 readers 會退回使用此值顯示/V 與 /DV。不解析 /RV 的讀取器
RichValue - PDF 1.7 Annex L tagged XHTML body (the most portable form starts with <?xml version="1.0"?> and an XHTML <body> root carrying the xfa:contentType="text/html" namespace attribute). Inline styling uses <span style="..."> with CSS properties (font-family, font-size, font-weight, font-style, color, etc.).
DefaultStyle - CSS-like style string applied to characters the user types at fill time when no per-character style is present in /RV. Example: 'font: 12pt Helvetica; color: #000000'.
Rectangle - widget 的 /Rect,使用 HotPDF 螢幕座標(左上原點);rect 轉換為 PDF 使用者空間時會自動套用 YProjection
MaxLen - optional; when greater than zero, emits a /MaxLen entry capping the user-entered character count. Defaults to 0 (no limit).
Flags - 選用;除了自動加入的 RichText bit 之外,任何要 OR 到 /Ff 的額外 field flags。常見額外 flags:ffMultiline 用於多段落 rich-text bodies,ffReadOnly 用於僅顯示的 formatted text。ffRichText flag 一律會加入,因此呼叫端不需要包含它
Code Example
// Rich-text Tx widget with bold + italic markup
var
Rich, DS: AnsiString;
R: TRect;
begin
HPDF.BeginDoc;
Rich :=
'<?xml version="1.0"?>' +
'<body xmlns="http://www.w3.org/1999/xhtml" ' +
'xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" ' +
'xfa:contentType="text/html">' +
'<p style="font-family:Helvetica;font-size:12pt">' +
'<span style="font-weight:bold">Bold</span> and ' +
'<span style="font-style:italic">italic</span> text.' +
'</p></body>';
DS := 'font: 12pt Helvetica; color: #000000';
R.Left := 60; R.Top := 60; R.Right := 280; R.Bottom := 100;
HPDF.CurrentPage.AddRichTextField(
'Biography', 'Plain biography text', Rich, DS, R);
HPDF.EndDoc;
end;
請參閱
AddTextField, AutoFormAppearances, Version, AcroForm 支援
|