DrawBoxWithText

Draws a box with text for the given width and height at the specifiy location.

DrawBoxWithText(xText As Single, yText As Single, Text As String, FontDictionaryName As String,
                FontSize As Single, TextAlignment As Single, TextColor As Color, xBox As Single,
                yBox As Single, BoxWidth As Single, BoxHeight As Single, BorderColor As Color,
                BorderThickness As Single, Optional BoxCapStyle As pdf.LineCapStyle)

Values passed to this procedure:

xText, yTextx, y coordinates on the page you want to draw the text.
TextThe text to draw.
FontDictionaryNameThe name used to reference the font within the document Font Dictionary. The FontDictionaryName is assigned to the font when you call LoadFont.
FontSizeFont size to be used.
TextAlignmentText alignment (Center, Left or Right).

If the text alignment is left, it is the text beginning position. If the alignment is right, its the ending position. If the alignment is center, its the middle position.
TextColorColor of the text.
xBox, yBoxx, y coordinates on the page you want to draw the box. This is the top left position of the box.
BoxWidthBox width.
BoxHeightBox height.
BorderColorColor of box border.
BorderThicknessThickness of the border.
BoxCapStyleOptional. The box cap style specifies the shape to be used at the ends of each line that makes up the box. The three types are:

Squared - the stroke is squared off at the endpoint of the path. There is no projection beyond the end of the path.

Round - a semicircular arc with a diameter equal to the line width is drawn around the endpoint and filled in.

ProjectingSquare - The stroke continues beyond the endpoint of the path for a distance equal to half the line width and is squared off.

The default is Squared.

Examples

DrawBoxWithText(PageWidthInInch / 2, PageHeightInInch - 0.5, "Text in a Box", "ArialBold", 10,
                pdf.TextAlignment.Center, Color.Black, 0.25, PageHeightInInch - 0.35,
                PageWidthInInch - 0.5, 0.2, Color.Black, 0.01, pdf.LineCapStyle.Squared)
Sample text in box

The following example uses the GetTextLength function to auto size the the width of the box, based on the width of the text to be dispalyed inside of the box. Because the text x coordinate is 1, the box x coordinate will be .9 (this will leave 1 tenth of an inch between the left border of the box and the first character of text. The box y coordinate will be the value returned by GetTextLength + 2 tenth of an inch.

DrawBoxWithText(1, PageHeightInInch - 2, "Red text, left align in a blue box", "ComicBoldItalic", 25,
                pdf.TextAlignment.Left, Color.Red, 0.9, .PageHeightInInch - 1.63,
                .GetTextLength("Red text, left align in a blue box", "ComicBoldItalic", 25) + 0.2, 0.5,
                Color.Blue, 0.03, pdf.LineCapStyle.Round)
Sample text in box