0

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>

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

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

But the PDColor is only change the background color, not my expectation. May I know how to set the font color on it?

This is my sample file: https://1.bitsend.jp/download/c10903041b8af47195daeef1f471a366.html

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97
b7184756
  • 45
  • 4
  • The `PDFreeTextAppearanceHandler` uses the last non stroking color in /DA for the text and the border (because that is what Adobe does). But from your example I see that if there is a different color in /DS then that one is to be used for the text color. I'll fix that in the repository tonight. – Tilman Hausherr Aug 12 '19 at 11:18
  • In general there only is limited support for rich text information (like in the **DS** entry) in PDFBox, Often merely the basic text information (like in the **DA** entry) are used. Thus, you should have the correct information already in the basic text information where possible. – mkl Aug 12 '19 at 11:31
  • I have updated the repository, the changes are in http://svn.apache.org/viewvc?rev=1864976&view=rev . – Tilman Hausherr Aug 12 '19 at 15:53
  • Just tried the changes, seems the regex ```COLOR_PATTERN``` cannot match the strings. After modified the regex to ```".*#([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]).*"```, it is able to change the font color now. Thanks!! – b7184756 Aug 13 '19 at 10:28
  • Could be because of the space after "color:". I didn't test with your files (because there are already annotations in the base file), I tested with a file that I created with Adobe Reader and then removed the /AP. I'll add an optional space sequence to the regex. – Tilman Hausherr Aug 13 '19 at 12:44

1 Answers1

0

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.

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97