PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Expanding rectangle text
http://forum.pdfsharp.de/viewtopic.php?f=2&t=1548
Page 1 of 1

Author:  paulv [ Wed Feb 16, 2011 3:06 pm ]
Post subject:  Expanding rectangle text

If I create a rectangle and place text into it with :

rect = new XRect(310, 100, 250, 220);
gfx.DrawRectangle(XBrushes.SeaShell, rect);
tf.Alignment = XParagraphAlignment.Right;
tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

but the text is more than the size of the rectangle, is there a way for the rectangle to expand to fit the amount of text or is that not possible with pdfsharp ? Maybe I have to use MigraDoc instead.

Paul

Author:  Thomas Hoevel [ Wed Feb 16, 2011 3:25 pm ]
Post subject:  Re: Expanding rectangle text

Calculate the size of the text, then draw a rectangle that is large enough, then draw the text.

You could use XGraphics.MeasureString.

Author:  paulv [ Thu Feb 17, 2011 11:42 am ]
Post subject:  Re: Expanding rectangle text

That is interesting way of doing it.

I can see that I can get the size using MeasureString which returns the width and height of 1148 and 265 but I can't see how I relate that to a different sized box.

So if I want a box of width 900 I can't see how I calculate the height.

Paul

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