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.
Unfortunately, activation email could not send to your email. Please try again.

Determine string width

Thread ID:

Created:

Updated:

Platform:

Replies:

94852 Jun 4,2010 05:05 PM Jun 8,2010 05:23 AM ASP.NET Web Forms (Classic) 1
loading
Tags: PDF
Theo
Asked On June 4, 2010 05:05 PM

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

Sundaram R [Syncfusion]
Replied On June 8, 2010 05:23 AM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;