PDFSharp supports automatic text wrapping when drawing long text portions:
textFormatter.DrawString(text, font, XBrushes.Black, new XRect(x, y, textAreaWidth, 1000), XStringFormats.TopLeft);
This will wrap the text if it is longer than textAreaWidth
.
How can I get the height of the text that has just been drawn?
I tried it with gfx.MeasureString()
, but there is no overload that supports specifying a maximal width. gfx.MeasureString()
returns the size of the text without text wrapping.
Thanks for any hints.
I found this extension of PdfSharp to be the answer to this problem:
You can clone or fork the relevant code here:
https://github.com/yolpsoftware/PdfSharp/tree/measure-text-height