Rich text support in FreeText Annotations

Q: can you provide me sample code to create a freetext-annotation with
richtext-content?

A: You could store richtext-content under “RC” key in FreeText
annotation. For example:

Page page = doc.GetPage(1);
pdftron.PDF.Annots.FreeText t = pdftron.PDF.Annots.FreeText.Create(doc, new Rect(85, 458, 503, 502));
t.SetContents("Hello World");
t.GetSDFObj().PutString("RC", "<?xml version=\"1.0\"?><body xmlns=
\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/
xfa-data/1.0/\" xfa:APIVersion=\"Acrobat:9.3.3\" xfa:spec=\"2.0.2\"
style=\"font-size:12.0pt;text-align:left;color:#FF0000;font-
weight:normal;font-style:normal;font-family:Helvetica,sans-serif;font-
stretch:normal\"><p dir=\"ltr\"><span style=\"font-family:Helvetica
\">Hello </span><span style=\"color:#00AA00;font-style:italic;font-
family:Helvetica\">World</span></p></body>");
t.RefreshAppearance();
page.AnnotPushBack(t);

Note that when an annotation contains Rich Text content, styling information is from the above content, and other annotation styling information is ignored.

Here is a table of the currently supported Rich text tags

Supported HTML tags Supported css style properties
body font-family
p font-size
span color
text-align
font-weight
font-style
font-stretch
line-height
text-decoration
font
1 Like