简体   繁体   English

如何从 acroform 获取字体颜色?

[英]How to get font color from acroform?

I using itext7 and I need to get font color from acroform in the pdfformfield.我使用itext7 ,我需要从 pdfformfield 中的 acroform 获取font color
I didn't find this property in PdfFont .我没有在PdfFont找到这个属性。
How can I do it?我该怎么做?

The text color from the form field default appearance can be retrieved using可以使用以下方法检索表单字段默认外观中的文本颜色

Color textColor = field.getColor();

for a PdfFormField field .对于PdfFormField field

Please beware, though:不过请注意:

  • iText 7 only extracts text colors set using one of the operators g , rg , and k which are the convenience operators for setting DeviceGray , DeviceRGB , and DeviceCMYK nonstroking colors respectively. iText 7 仅提取使用运算符grgk之一设置的文本颜色,这些运算符分别是设置DeviceGrayDeviceRGBDeviceCMYK 非描边颜色的便捷运算符。 If the color is selected using a different operator or there is no color setting operator at all, null will be returned.如果使用不同的运算符选择颜色或根本没有颜色设置运算符,则将返回null

    I've not yet observed a PDF with form field default appearances using other color setting operators.我还没有观察到使用其他颜色设置运算符具有表单字段默认外观的 PDF。 In my experience, therefore, that implementation is sufficient.因此,根据我的经验,这种实施就足够了。

  • If the field is a rich text field, the default style string may overrule anything in the default appearances, so the color retrieved using getColor() may be incorrect.如果字段是富文本字段,则默认样式字符串可能会覆盖默认外观中的任何内容,因此使用getColor()检索的颜色可能不正确。

    In this situation, though, a user filling in the field is free to use different colors.但是,在这种情况下,填写该字段的用户可以自由使用不同的颜色。 Thus, in this case an attempt to retrieve "the text color of the field" is questionable anyways.因此,在这种情况下,尝试检索“字段的文本颜色”无论如何都是有问题的。

  • A PDF processor or JavaScript code in PDFs can ignore or override the default appearance color. PDF 中的 PDF 处理器或 JavaScript 代码可以忽略或覆盖默认外观颜色。 Thus, you never can be sure that the color returned here actually is the color a user will eventually perceive the text color as.因此,您永远无法确定此处返回的颜色实际上是用户最终将文本颜色视为的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM