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

Calculating text width
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2043
Page 1 of 1

Author:  lala [ Wed Jun 06, 2012 3:20 pm ]
Post subject:  Calculating text width

Hi,

I'm trying to calculate text width and determine number of columns the page can contain. I found XGraphics, which has method MeasureString() that return a XSize, but I'm not sure what the unit of that is and how that turns into Unit:

Code:
XGraphics graphics = XGraphics.CreateMeasureContext(new XSize(8.5, 11), XGraphicsUnit.Inch, XPageDirection.Downwards);
Document document = new Document();
Section section = this.Document.AddSection();
Table table = section.AddTable();

string text = "some column text";
XSize size = Graphics.MeasureString(text, new XFont("Arial", 1.2));
Column column = table.AddColumn(/* size to unit here*/);

Author:  lala [ Wed Jun 06, 2012 3:44 pm ]
Post subject:  Re: Calculating text width

Hmm...I think TextMeasurement is what I should use instead here, so nvm :D

Author:  Thomas Hoevel [ Wed Jun 06, 2012 4:07 pm ]
Post subject:  Re: Calculating text width

Hi!

XSize contains the Width and the Height (both values use the unit Point).

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