PDFSharp:测量长文本的高度与自动换行 [英] PDFSharp: Measuring height of long text with word wrap
问题描述
PDFSharp支持自动文字换行绘制长度的文本部分时:
PDFSharp supports automatic text wrapping when drawing long text portions:
textFormatter.DrawString(text, font, XBrushes.Black, new XRect(x, y, textAreaWidth, 1000), XStringFormats.TopLeft);
这将自动换行,如果它比 textAreaWidth $ C更长$ C>。
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?
我与 gfx.MeasureString()
试了一下,但没有重载支持指定的最大宽度。 gfx.MeasureString()
返回文本无文本换行的大小。
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.
感谢您的任何提示。
推荐答案
我发现这个扩展PdfSharp的是回答这个问题:
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
这篇关于PDFSharp:测量长文本的高度与自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!