PDTextField 可以设置带有 alpha 值的文本颜色吗?
Can PDTextField set a text color with an alpha value?
我目前正在设置默认外观字符串来设置文本颜色,如下所示:
String defaultAppearance = "/Helv 12 Tf 0 0 1 rg";
field.setDefaultAppearance(defaultAppearance);
除了 RGB 的 rg 或黑白的 g 之外,我似乎找不到任何其他格式字符串选项。
有没有办法将文本颜色设置为 rgba 颜色、设置文本 alpha 或我可以查看的有关默认外观字符串格式的文档?
您正在寻找关于默认外观字符串格式的文档。您可以在 PDF 规范 ISO 32000 中找到(惊喜!):
DA string (Required; inheritable) The default appearance string containing a sequence of valid page-content graphics or text state operators that define such properties as the field’s text size and colour.
(ISO 32000-2, Table 228 — 包含可变文本的所有字段共有的附加条目)
然后更详细地,
The default appearance string (DA) contains any graphics state or text state operators needed to establish the graphics state parameters, such as text size and colour, for displaying the field’s variable text. Only operators that are allowed within text objects shall occur in this string (see "Figure 9 — Graphics objects"). At a minimum, the string shall include a Tf (text font) operator along with its two operands, font and size. The specified font value shall match a resource name in the Font entry of the default resource dictionary (referenced from the DR entry of the interactive form dictionary; see "Table 224 — Entries in the interactive form dictionary"). A zero value for size means that the font shall be auto-sized: its size shall be computed as an implementation dependent function.
The default appearance string shall contain at most one Tm (text matrix) operator. If this operator is present, the interactive PDF processor shall replace the horizontal and vertical translation components with positioning values it determines to be appropriate, based on the field value, the quadding (Q) attribute, and any layout rules it employs. If the default appearance string contains no Tm operator, the viewer shall insert one in the appearance stream (with appropriate horizontal and vertical translation components) after the default appearance string and before the text-positioning and textshowing operators for the variable text.
(ISO 32000-2 第 12.7.4.3 节 — 可变文本)
根据图 9,文本对象中允许的操作 类 是:
其中Text Showing和Marked Content算子不是图形状态或文本状态算子,因此可用的算子是:
- 一般图形状态 w,J,j,M,d,ri,i,gs
- 颜色 CS, cs, SC, SCN, sc, scn, G, g, RG, rg, K, k
- 文本状态 Tc, Tw, Tz, TL, Tf, Tr, Ts
- 文本定位 Td, TD, Tm, T*
(ISO 32000-2, Table 50 — 运营商类别)
显然我不能在这里复制所有这些运算符的规范。
不过,特别感兴趣的是通用图形状态运算符 gs,它允许您使用 ExtGState 资源来设置蒂尔曼在对您的问题的评论中已经提出的透明度。
不过,请注意,许多 pdf 处理器只需要字体设置 (Tf) 和简单的颜色设置 (rg / g / k) 操作并忽略其他一切。
我目前正在设置默认外观字符串来设置文本颜色,如下所示:
String defaultAppearance = "/Helv 12 Tf 0 0 1 rg";
field.setDefaultAppearance(defaultAppearance);
除了 RGB 的 rg 或黑白的 g 之外,我似乎找不到任何其他格式字符串选项。
有没有办法将文本颜色设置为 rgba 颜色、设置文本 alpha 或我可以查看的有关默认外观字符串格式的文档?
您正在寻找关于默认外观字符串格式的文档。您可以在 PDF 规范 ISO 32000 中找到(惊喜!):
DA string (Required; inheritable) The default appearance string containing a sequence of valid page-content graphics or text state operators that define such properties as the field’s text size and colour.
(ISO 32000-2, Table 228 — 包含可变文本的所有字段共有的附加条目)
然后更详细地,
The default appearance string (DA) contains any graphics state or text state operators needed to establish the graphics state parameters, such as text size and colour, for displaying the field’s variable text. Only operators that are allowed within text objects shall occur in this string (see "Figure 9 — Graphics objects"). At a minimum, the string shall include a Tf (text font) operator along with its two operands, font and size. The specified font value shall match a resource name in the Font entry of the default resource dictionary (referenced from the DR entry of the interactive form dictionary; see "Table 224 — Entries in the interactive form dictionary"). A zero value for size means that the font shall be auto-sized: its size shall be computed as an implementation dependent function.
The default appearance string shall contain at most one Tm (text matrix) operator. If this operator is present, the interactive PDF processor shall replace the horizontal and vertical translation components with positioning values it determines to be appropriate, based on the field value, the quadding (Q) attribute, and any layout rules it employs. If the default appearance string contains no Tm operator, the viewer shall insert one in the appearance stream (with appropriate horizontal and vertical translation components) after the default appearance string and before the text-positioning and textshowing operators for the variable text.
(ISO 32000-2 第 12.7.4.3 节 — 可变文本)
根据图 9,文本对象中允许的操作 类 是:
其中Text Showing和Marked Content算子不是图形状态或文本状态算子,因此可用的算子是:
- 一般图形状态 w,J,j,M,d,ri,i,gs
- 颜色 CS, cs, SC, SCN, sc, scn, G, g, RG, rg, K, k
- 文本状态 Tc, Tw, Tz, TL, Tf, Tr, Ts
- 文本定位 Td, TD, Tm, T*
(ISO 32000-2, Table 50 — 运营商类别)
显然我不能在这里复制所有这些运算符的规范。
不过,特别感兴趣的是通用图形状态运算符 gs,它允许您使用 ExtGState 资源来设置蒂尔曼在对您的问题的评论中已经提出的透明度。
不过,请注意,许多 pdf 处理器只需要字体设置 (Tf) 和简单的颜色设置 (rg / g / k) 操作并忽略其他一切。