I am generating a report with text from a database. I would like to place two pieces of text side-by-side on the PDF, but I don't know at which coordinates to place the second piece of text, because I don't know how long the first piece of text will be. Is there a way to dynamically determine how wide rendered text will be?
Getting the size of text at run-time
Re: Getting the size of text at run-time
Support · Jan 20, 2006You can get this information off of the Font classes GetTextWidth
method. If you are using Helvatica, 12 Point:
TextWidth = Font.Helvetica.GetTextWidth( "My Text", 12 )
If you are using a TrueType, Type 1 or other font object:
TextWidth = MyFont.GetTextWidth( "My Text", 12 )
This will give you the width of the text. You can then add this to the X value to determine where to start the second piece of text.
Thanks,
ceTe Software Support Team