|
向当前页面添加 PDF 1.5+ AcroForm 富文本文本控件(ISO 32000-1 12.7.4.3 + Annex L)。该控件携带不解析富文本的阅读器所用的标准 /V + /DV 纯文本回退,外加 Acrobat 和 Foxit 可直接消费以渲染带样式文本的 /RV 富文本 XHTML 正文与 /DS 默认样式条目。/Ff 的 RichText 位(26)自动置入。
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());
说明
控件作为 Tx 表单字段输出,带 /FT /Tx、/DA (/Helv 12 Tf 0 0 0 rg)、置了 RichText 位的 /Ff;提供的 InitialValue 同时写为 /V 与 /DV,RichValue 写为 /RV,DefaultStyle 写为 /DS。InitialValue、RichValue 与 DefaultStyle 自动检测多字节内容,需要时切换到 UTF-16BE 十六进制字符串编码(与国际纯文本字段的既有 AddTextField 行为一致)。
富文本渲染发生在阅读器中:RichText 位打开时,Acrobat / Foxit / Edge / Chrome PDF 查看器都会解析 /RV 并从系统获取 Unicode 字体回退,因此 CJK、西里尔、阿拉伯与带变音符的拉丁内容无需 HotPDF 向 /DR Resources 嵌入 CID 字体即可正确显示。HotPDF 自身的 AutoFormAppearances 路径仍保留多字节文本的占位空 AP 分支(v2.56.0+ 任务);支持富文本的阅读器忽略该 AP,直接从 /RV 渲染。
FieldName - PDF 表单字段的 /T 局部名(须在其父级内唯一)。接受空格与非 ASCII 字节;非 ASCII 触发输出的 /T 字符串使用 UTF-16BE 编码。
InitialValue - 写入 /V 与 /DV 的纯文本 PDF 字符串。不解析 /RV 的阅读器回退到此值显示。
RichValue - PDF 1.7 附录 L 的带标签 XHTML 正文(最通用的形式以 <?xml version="1.0"?> 开头,根为 XHTML <body>,并带有 xfa:contentType="text/html" 命名空间属性)。行内样式使用 <span style="...">,并配合 CSS 属性(font-family、font-size、font-weight、font-style、color 等)。
DefaultStyle - 类 CSS 的样式字符串,应用于用户在填写时输入、且 /RV 中没有逐字符样式的字符。示例:'font: 12pt Helvetica; color: #000000'。
Rectangle - 控件在 HotPDF 屏幕坐标(左上原点)中的 /Rect;矩形转换到 PDF 用户空间时自动执行 Y 投影。
MaxLen - 可选;大于零时输出 /MaxLen 条目,限制用户输入的字符数。默认为 0(不限制)。
Flags - 可选;在自动添加的 RichText 位之外,要 OR 进 /Ff 的额外字段标志。典型的额外标志:用于多段富文本正文的 ffMultiline,用于仅显示的格式化文本的 ffReadOnly。ffRichText 标志总会被添加,因此调用方无需再包含它。
代码示例
// 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 支持
|