The
XGraphics.DrawString(...) method does not handle line breaks (newlines) as the .NET Graphics.DrawString(…) method does.
Instead, PDFSharp will output something like blanks for \r and \n.
This is a little bit trickier to work around. You need an
XTextFormatter, a
XRect for the region which is available for the layouter and then call DrawString(…) on the formatter instead of the XGraphics object:
var formatter = new XTextFormatter(pageGraphics);
var layoutRectangle = new XRect(10, 10, page.Width, page.Height);
formatter.DrawString("Hello\r\nWorld", arial, XBrushes.Black, layoutRectangle);
Generating PDFs with PDFSharp[
^]