PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 05, 2024 8:22 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed May 08, 2013 7:37 am 
Offline

Joined: Tue Apr 30, 2013 2:38 pm
Posts: 5
Hi,

I'm new in this forum and I have started using PDF# a few days ago. I have a problem, in the pdf document I want to draw a string from a rich text box in a rectangle, but when the document is created the string goes out of the page (picture below). I have followed your examples on allining text and using text formatter, on pdf wiki, but with no success.

Image

Here is my code:

PdfDocument doc = new PdfDocument();
doc.Info.Title = "Test";

PdfPage page = doc.AddPage();

XGraphics gfx = XGraphics.FromPdfPage(page);

XFont font = new XFont("Arial", 14, XFontStyle.Regular);

XRect rect = new XRect(60, 75, 350, 150);
gfx.DrawRectangle(XBrushes.Black, rect);

XStringFormat format = new XStringFormat();

gfx.DrawString(rchtxtbxText.Text, font, XBrushes.Red, rect, format);

const string file = "Test.pdf";
doc.Save(@"C:\...\Desktop\" + file);

I would like to know how to draw a string in a rectangle. If someone could help me or give me some examples I would appreciate it. Thanks in advance and sorry for my bad english


Top
 Profile  
Reply with quote  
PostPosted: Wed May 08, 2013 9:17 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!

You have to use XTextFormatter to get more than a single line automatically.
With gfx.DrawString you will always get a single line only.

Link to sample code:
http://www.pdfsharp.net/wiki/TextLayout-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 08, 2013 9:48 am 
Offline

Joined: Tue Apr 30, 2013 2:38 pm
Posts: 5
I get the same result, the text is not alligned in the rectangle, is in one line and it's out of page bounds like in the picture i posted. In the Xtextformatter example you have a const string text variable which has a defined string length in every row or has ("\n") to jump in a new line, otherwise I get the string from a rich text box which has word wrap enabled


Top
 Profile  
Reply with quote  
PostPosted: Wed May 08, 2013 11:47 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
XTextFormatter breaks lines only at spaces. Use useful test text and it'll work.
Or modify XTextFormatter to your needs.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 08, 2013 2:52 pm 
Offline

Joined: Tue Apr 30, 2013 2:38 pm
Posts: 5
It works. Thanks a lot for your support

Regards,
saks07


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 77 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group