Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFsharp Line Break

I am trying to get new line but if I use \n it does not work.

Any way to have new line by adding something to string like \r\n (which also does not work)

gfx.DrawString("Project No \n" + textBoxProjNumber.Text, fontUnder, XBrushes.Black, 230, 95); 

(the example snippet shows what I've tried but does not work).

like image 418
Afnan Bashir Avatar asked Mar 15 '11 22:03

Afnan Bashir


1 Answers

Have you tried the XTextFormatter class?

See here: http://www.pdfsharp.net/wiki/TextLayout-sample.ashx

Code snippet:

PdfDocument document = new PdfDocument();  PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold); XTextFormatter tf = new XTextFormatter(gfx);  XRect rect = new XRect(40, 100, 250, 220); gfx.DrawRectangle(XBrushes.SeaShell, rect); tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); 
like image 71
I liked the old Stack Overflow Avatar answered Sep 25 '22 03:09

I liked the old Stack Overflow