2

Referring to Build text callout with PDF Clown - Is there a possibility to change the font color of the text within the callout note?

I haven't found a suitable method yet, can someone please give me a hint?

Community
  • 1
  • 1
grml
  • 23
  • 3

1 Answers1

1

There is no explicit PDF Clown method to set the text color. This might be related to the fact that there is no explicit entry in the PDF annotation dictionary for it either.

There are two options, though:

  • There is a default appearance (DA) entry for variable text in annotations in general. As PDF Clown does not hide generic object methods, you can extend the original callout sample like this:

    // Callout.
    composer.showText("Callout note annotation:", new Point(35, 85));
    new StaticNote(
      page,
      new Rectangle(250, 90, 150, 70),
      "Text of the Callout note annotation"
      ).withLine(
         new StaticNote.CalloutLine(
           page,
           new Point(250,125),
           new Point(150,125),
           new Point(100,100)
           )
         )
       .withLineEndStyle(LineEndStyleEnum.OpenArrow)
       .withBorder(new Border(1))
       .withColor(DeviceRGBColor.get(Color.YELLOW))
       .getBaseDataObject().put(PdfName.DA, new PdfString("1 0 1 rg /Ti 12 Tf"));
    

    You have to use plain PDF instructions there, though, rg sets a RGB color defined by the three preceding values, and Tf sets font and size according to the preceding two values. The result of the above is:

    Excerpt from AnnotationSample (with the addition above) output

    As you see, the text now is purple (red 100%, green 0%, blue 100%). A side effect is, though, that the callout line and the frame around the callout box also are purple.

  • Alternatively a PDF can bring along an own appearance stream defining the whole appearance of the annotation in question. This means, though, that you really have to draw everything yourself including lines, frames, backgrounds, and text.

    PDF Clown allows you to set the appearance of an annotation using the setAppearance and withAppearance methods.

mkl
  • 90,588
  • 15
  • 125
  • 265
  • The first option works well @mkl, but we need to change only the font color. Also I tried the methods setAppearance and withAppearance. Do you have some sample code? I had a closer look into the Appearance object with the following output (from StaticNote.getAppearance): „CreationDate (...) Rect [ 569.5875000000001 756.641 581.5875000000001 769.641 ] F 4 CL [ 389.06100000000004 760.9929999999999 543.6750000000001 760.9929999999999 569.5875000000001 763.141 ] IT FreeTextCallout M (...) AP << >> P 3 0 R BS 152 0 R Type Annot Contents (C) LE [ None OpenArrow ] Subtype FreeText“ – grml Sep 22 '16 at 12:01
  • @grml I'll look into that later the coming week. – mkl Sep 25 '16 at 20:35