我们正在使用XFinium PDF库从移动设备生成PDF文档。我们使用代码示例来编写包装文本,如下所示:
PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
sao.Brush = brush;
sao.Font = helvetica;
// Height is not set, text has no vertical limit.
PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
slo.HorizontalAlign = PdfStringHorizontalAlign.Justified;
slo.VerticalAlign = PdfStringVerticalAlign.Top;
slo.X = 20;
slo.Y = 70;
slo.Width = 280;
string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
"Sed vel euismod risus. Fusce viverra, nisi auctor ullamcorper porttitor, " +
"ipsum lacus lobortis metus, sit amet dictum lacus velit nec diam. " +
"Morbi arcu diam, euismod a auctor nec, aliquam in lectus." +
"Ut ultricies iaculis augue sit amet adipiscing. Aenean blandit tortor a nisi " +
"dignissim fermentum id adipiscing mauris. Aenean libero turpis, varius nec ultricies " +
"faucibus, pretium quis lectus. Morbi mollis lorem vel erat condimentum mattis mollis " +
"nulla sollicitudin. Nunc ut massa id felis laoreet feugiat eget at eros.";
page.Graphics.DrawString(text, sao, slo);
但是,如果我们不知道下一个y坐标是什么,我们如何在此下面绘制另一个字符串?有没有办法计算现有文本的高度或找出可用的y坐标是什么?
感谢。
答案 0 :(得分:6)
Xfinium.Pdf.Graphics.Text.PdfTextEngine类包含静态方法GetStringHeight(字符串s,PdfFont字体,双倍宽度)。传入要绘制的字符串,用于绘制字符串的字体和文本将包装的宽度,方法将返回包装的高度
文本。
对于您的代码片段,调用如下所示:
double textHeight = PdfTextEngine.GetStringHeight(text, helvetica, slo.Width);
免责声明:我为开发XFINIUM.PDF库的公司工作。