Q: How to create a border around Text Element
---
A:
After creating a text-run element (e.g. as in ElementBuilder sample
project - http://www.pdftron.com/net/samplecode.html#ElementBuilder)
you can obtain the bounding box using element.GetBBox(rect). Then you
can use the bounding box information to create a stroked path that
surrounds the text.
For example:
...
eb is ElementBuilder
writer is ElementWriter
...
// Begin writing a block of text
Element element = eb.CreateTextBegin(Font.Create(doc,
Font.StandardType1Font.e_times_roman), 12);
writer.WriteElement(element);
string data = "Hello World!";
element = eb.CreateTextRun(data);
element.SetTextMatrix(10, 0, 0, 10, 0, 600);
Rect bbox = new Rect();
element.GetBBox(bbox);
writer.WriteElement(element);
// Finish the block of text
writer.WriteElement(eb.CreateTextEnd());
// Now draw a red rectangle around the text...
element = eb.CreateRect(bbox.x1, bbox.y1, bbox.x2, bbox.y2);
element.SetPathStroke(true);
// Set the path color space and color
GState gstate = element.GetGState();
gstate.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
gstate.SetFillColor(new ColorPt(1, 0, 0)); // red
gstate.SetLineWidth(2);
writer.WriteElement(element); // draw the rectangle
...