PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Dynamically determine width based on string width
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1385
Page 1 of 1

Author:  iandawg [ Thu Oct 21, 2010 7:40 pm ]
Post subject:  Dynamically determine width based on string width

Is there a method similar to .MeasureString that returns the width? I need to position a second font element based on on how long the first.

Author:  mikesowerbutts [ Fri Oct 22, 2010 8:33 am ]
Post subject:  Re: Dynamically determine width based on string width

Hi,

Yes there is. Its a method in the XGraphics class called MeasureString....

to get an XGraphics object you do XGraphics.FromPdfPage(yourPageHere), where your page here could be something like myPdfDocument.Pages[0] etc.

The XGraphics MeasureString() method basically works like the normal MeasureString, but yuu pass in the relevant font ( i presume its a XFont, but havnt checked - intellisense will tell you though... ) and the string you wish to measure, the function will then return a XRectangle or something like that, which you can get the width from.

Hope this helps

Mike

Author:  iandawg [ Mon Nov 01, 2010 8:48 pm ]
Post subject:  Re: Dynamically determine width based on string width

Thanks! Worked like a champ!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/