Both PDFsharp and PdfSharpCore provide the XTextFormatter
class. This class is a lifesaver when it comes to printing blocks that require word wrap.
But here's my question: What if I need to print multiple paragraphs? How can I determine where the bottom of the paragraph just printed is?
XTextFormatter.DrawString()
returns void
, so it doesn't tell me how far down it got. And there are no overloads that accept a new Y position or rectangle. And the only similar property, LayoutRectangle
, simply contains the rectangle that I passed to DrawString()
. And XTextFormatter
has no MeasureString()
method.
So how is it possible to print multiple paragraphs, one just below the previous?
The answer is that this is not supported. Surprisingly, the author of the
XTextFormatter
class chooses not to expose this information and keeps the current Y position internal to that class.Fortunately, both PDFsharp and PdfSharpCore are open source. You can download the
XTextFormatter
code and tweak it to your heart's content. Or you can work from the version in this discussion.