简体   繁体   English

如何使用pdfbox 2.0.16设置PDAnnotationFreeText的字体颜色

[英]How to set the font color for PDAnnotationFreeText with using pdfbox 2.0.16

After imported XFDF to FDFAnnotation and converted to PDAnnotation, I find that the font color of PDAnnotationFreeText is missing. 将XFDF导入FDFAnnotation并转换为PDAnnotation后,我发现PDAnnotationFreeText的字体颜色丢失。

<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>

and this is the details after import to FDFAnnotation 这是导入到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};
}

I have extract the color hex code and tried to convert to PDColor 我已经提取了十六进制颜色的代码,并试图转换为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);

But the PDColor is only change the background color, not my expectation. 但是PDColor仅改变背景颜色,而不是我的期望。 May I know how to set the font color on it? 我可以知道如何设置字体颜色吗?

This is my sample file: https://1.bitsend.jp/download/c10903041b8af47195daeef1f471a366.html 这是我的示例文件: https : //1.bitsend.jp/download/c10903041b8af47195daeef1f471a366.html

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() ). 这将在PDFBox 2.0.17中修复,将同时考虑/ DS条目的颜色( annotation.getDefaultStyleString() .getDefaultStyleString annotation.getDefaultStyleString() ),并且其优先级高于/ DA条目的颜色( annotation.getDefaultAppearance() )。 The new implementation can be seen here , a snapshot is available here . 这里可以看到新的实现,在这里可以找到快照。

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

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