Panikmeister86
Panikmeister86

Reputation: 3

How to change font color and fontsize of FreeTextAnnotations (itext 7)?

i create a PdfFreeTextAnnotation but the setColor-Method is only für the background of the Annotation.

How to set the actual fontcolor, fontsize and font?

Dim rec As iText.Kernel.Geom.Rectangle = ...

Dim anno As Annot.PdfFreeTextAnnotation = New 
Annot.PdfFreeTextAnnotation(rec, New PdfString(_annotation.Text))

anno.SetName(New PdfString(_annotation.Name))
anno.SetFlags(192)

anno.SetBorder(New iText.Kernel.Pdf.PdfAnnotationBorder(0, 0, 0))

pdfDoc.GetPage(_annotation.PageNumber).AddAnnotation(anno)

Upvotes: 0

Views: 730

Answers (1)

Alexey Subach
Alexey Subach

Reputation: 12312

FreeText annotations have RC key that allows setting a rich text string that shall be used to generate the appearance of the annotation. Basically you can use plain HTML as a rich text string, e.g. you can wrap some text in a <span> and set the text color in style attribute of that span, just as in HTML.

Here is the code in C# that does the trick:

anno.SetRichText(new PdfString("<span style=\"color:#10FF10;\">Hello world</span>"));

Upvotes: 1

Related Questions