Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFsharp word wrap

Tags:

c#

pdfsharp

How does one wrap text inside the rectangle using PDFsharp?

In my attempts the text still extends off the PDF's page. Here is what was tried:

rect = new XRect(20, 300, 400, 100);
tf.Alignment = XParagraphAlignment.Left;
gfx.DrawString("\t • Please call the borrower prior to closing and confirm your arrival time and the closing location. \n", font, XBrushes.Black, rect, XStringFormats.TopLeft);
rect = new XRect(20, 320, 100, 100);
gfx.DrawString("\t • If the borrower needs to change the closing appointment time or date for any reason please have them call McDonnell Law Firm at 866-931-8793 \n", font, XBrushes.Black, rect, XStringFormats.TopLeft);
rect = new XRect(20, 340, 100, 100);
gfx.DrawString("\t • Completed documents must be received same day. Fax back to 888-612-4912 or email [email protected] \n", font, XBrushes.Black, rect, XStringFormats.TopLeft);
rect = new XRect(20, 360, 100, 100);
gfx.DrawString("\t • Documents are to be returned via Fedex or UPS with shipping label provided. Documents must be dropped same day. \n", font, XBrushes.Black, rect, XStringFormats.TopLeft);

This is what it is doing > enter image description here

like image 959
MaylorTaylor Avatar asked Mar 28 '14 23:03

MaylorTaylor


1 Answers

From your code snippet I assume that tf is an object of the XTextFormatter class while gfx is an XGraphics object.

XGraphics.DrawString does not support line breaks.

XTextFormatter.DrawString supports line breaks.

The error in your code: you are calling gfx.DrawString where you meant to call tf.DrawString.

like image 134
I liked the old Stack Overflow Avatar answered Sep 21 '22 16:09

I liked the old Stack Overflow