如何使用 pdfbox 2.0.16 设置 PDAnnotationFreeText 的字体颜色 [英] How to set the font color for PDAnnotationFreeText with using pdfbox 2.0.16
问题描述
将XFDF导入FDFAnnotation并转换为PDAnnotation后,发现缺少PDAnnotationFreeText的字体颜色.
After imported XFDF to FDFAnnotation and converted to PDAnnotation, I find that the font color of PDAnnotationFreeText is missing.
<freetext page="0" rect="376.81193,778.184946,500.283994,807.936941" flags="print" name="373b558a-4892-5fb4-a9aa-b4d7175d3966" title="wwh" subject="Free text" date="D:20190808175721+08'00'" width="0" creationdate="D:20190808175700+08'00'" TextColor="#00CC63" FontSize="17">
<contents>English</contents>
<defaultappearance>0 0 0 rg /Arial 17 Tf</defaultappearance>
<defaultstyle>font: Arial 17pt; text-align: left; color: #00CC63</defaultstyle>
</freetext>
这是导入到 FDFAnnotation 后的细节
and this is the details after import to FDFAnnotation
COSDictionary{
COSName{Type}:COSName{Annot};
COSName{Page}:COSInt{0};
COSName{M}:COSString{D:20190808175721+08'00'};
COSName{F}:COSInt{4};
COSName{NM}:COSString{373b558a-4892-5fb4-a9aa-b4d7175d3966};
COSName{Rect}:COSArray{COSFloat{376.81192};COSFloat{778.18494};COSFloat{500.284};COSFloat{807.93695};};
COSName{T}:COSString{wwh};
COSName{CreationDate}:COSString{D:20190808175700+08'00'};
COSName{Subj}:COSString{Free text};
COSName{IT}:COSName{};
COSName{Contents}:COSString{English};
COSName{Subtype}:COSName{FreeText};
COSName{Q}:0;
COSName{DA}:COSString{0 0 0 rg /Arial 17 Tf};
COSName{DS}:COSString{font: Arial 17pt; text-align: left; color: #00CC63};
}
我已经提取了颜色十六进制代码并尝试转换为 PDColor
I have extract the color hex code and tried to convert to PDColor
int c = Integer.parseInt("#00CC63".substring(1), 16);
float r = ((c & 0xFF0000) >> 16) / 255f;
float g = ((c & 0x00FF00) >> 8) / 255f;
float b = ((c & 0x0000FF) >> 0) / 255f;
PDColor pdc = new PDColor( new float[] { r, g, b }, PDDeviceRGB.INSTANCE);
但 PDColor 只是改变背景颜色,不是我的期望.我可以知道如何设置字体颜色吗?
But the PDColor is only change the background color, not my expectation. May I know how to set the font color on it?
这是我的示例文件:https://1.bitsend.jp/download/c10903041b57a4f6f.html
推荐答案
这将在 PDFBox 2.0.17 中修复,/DS 条目 (annotation.getDefaultStyleString()
) 的颜色将是也考虑过,并且将优先于/DA 条目中的颜色(annotation.getDefaultAppearance()
).新的实现可以看 这里,快照可用 此处.
This will be fixed in PDFBox 2.0.17, the color of the /DS entry (annotation.getDefaultStyleString()
) will be considered too and will have priority over the color in the /DA entry (annotation.getDefaultAppearance()
). The new implementation can be seen here, a snapshot is available here.
这篇关于如何使用 pdfbox 2.0.16 设置 PDAnnotationFreeText 的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!