PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 04, 2024 3:26 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Expanding rectangle text
PostPosted: Wed Feb 16, 2011 3:06 pm 
Offline

Joined: Wed Feb 16, 2011 12:16 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 16, 2011 3:25 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Calculate the size of the text, then draw a rectangle that is large enough, then draw the text.

You could use XGraphics.MeasureString.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 17, 2011 11:42 am 
Offline

Joined: Wed Feb 16, 2011 12:16 pm
Posts: 4
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 38 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group