简体   繁体   English

如何截断边框内的文本?

[英]How can I truncate text within a bounding box?

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. 我直接使用PdfContentByte.showTextAligned将内容写入PdfContentByte对象,我想知道如何在写入时阻止文本溢出给定区域。

If possible it would be great if iText could also place an ellipsis character where the text does not fit. 如果可能的话,如果iText也可以在文本不适合的地方放置一个省略号,那就太好了。

I can't find any method on ColumnText that will help either. 我在ColumnText上找不到任何有帮助的方法。 I do not wish the content to wrap when writing. 我不希望在写作时将内容包装起来。

Use this: 用这个:

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

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. 确保以某种方式定义rectangle ,以便仅适合一行,请使用ColumnText.hasMoreText(status)来查找是否需要添加省略号字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM