change the background color of a text element in PDF

Q: We are using PDF tron to manage our pdf files…

We need to change the background color of a text element but could not found something relevant. We tried to use SetFillColor() but it is changing forcolor of text. Please advise us.

A: You would need to insert a renctange just before text is drawn. PDF does not have forecolor for text runs.

You could also use text highlight for a similar effect. With a text element, you can easily get its bounding box (via pdftron::PDF::Element::GetBBox()) that is specified in page space. With the bounding box, you can add text highlight annotation as follows:

Rect bbox = new Rect();

element.GetBBox(bbox);

pdftron.PDF.Annots.Highlight highlight = pdftron.PDF.Annots.Highlight.Create(pdf_doc_you_use, new Rect(bbox.x1, bbox.y1, bbox.x2, bbox.y2));

highlight.RefreshAppearance();

the_current_page.AnnotPushBack(highlight);