PDFSharp:测量长文本的高度与自动换行 [英] PDFSharp: Measuring height of long text with word wrap

查看:1411
本文介绍了PDFSharp:测量长文本的高度与自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

http://developer.th-soft.com/developer/2015/07/17/pdfsharp-improving-the-xtextformatter-class-measuring-the-height-of-the-text/

您可以克隆或派生的相关代码的位置:

You can clone or fork the relevant code here:

https://github.com/yolpsoftware/PdfSharp/tree/measure-text-height

这篇关于PDFSharp:测量长文本的高度与自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆