We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Determine string width

Hello,

Once I draw a string onto a pdf page. is it possible to determine the width of the string?

I want to use this information to align the string betwee two other objects.

Thank you

1 Reply

SR Sundaram R Syncfusion Team June 8, 2010 09:23 AM UTC

Hi Theo,

Thanks for using Syncfusion products.

You can use the type PdfTextElement to retrieve the width of the rendered string. Please find the code snippet below to do the same,

PdfDocument pdfDoc = new PdfDocument();

PdfPage page = pdfDoc.Pages.Add();

// Create a text element with text.
PdfTextElement element = new PdfTextElement("Test string", new PdfStandardFont(PdfFontFamily.TimesRoman, 2));

// Set the properties for the text element.
element.Brush = new PdfSolidBrush(System.Drawing.Color.Black);

// Draw the text element and store its layout information
PdfLayoutResult layoutResult = element.Draw(page, new PointF(5,5));

//Retrieve the rendered width of the text
float width = layoutResult.Bounds.Width;

Also for reference go through the content in the following URL,

http://help.syncfusion.com/ug_82/Reporting_PDF/DrawingText.html

If you have any further queries, please contact us.

Thanks,
Sundaram R.

Loader.
Live Chat Icon For mobile
Up arrow icon