如何在边界框内截断文本? [英] How can I truncate text within a bounding box?

查看:159
本文介绍了如何在边界框内截断文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PdfContentByte.showTextAligned 直接将内容写入 PdfContentByte 对象,我想知道如何我可以在写作时停止给定区域溢出的文本。

I am writing content to a PdfContentByte object directly using PdfContentByte.showTextAligned, I'd like to know how I can stop the text overflowing a given region when writing.

如果可能,如果iText也可以在文本不适合的地方放置省略号字符,那将会很棒。

If possible it would be great if iText could also place an ellipsis character where the text does not fit.

我在 ColumnText 上找不到任何方法。我不希望内容在写作时换行。

I can't find any method on ColumnText that will help either. I do not wish the content to wrap when writing.

推荐答案

使用此:

int status = ColumnText.START_COLUMN;
ColumnText ct = new ColumnText(cb);
ct.setSimpleColumn(rectangle);
status = ct.go();

确保在a中定义矩形这样只有一行适合,使用 ColumnText.hasMoreText(status)来确定是否需要添加省略号字符。

Make sure that you define rectangle in a way so that only one line fits, use ColumnText.hasMoreText(status) to find out if you need to add an ellipsis character.

这篇关于如何在边界框内截断文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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