How can I truncate text within a bounding box?

梦想与她 提交于 2020-01-11 11:30:10

问题


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.

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/13558135/how-can-i-truncate-text-within-a-bounding-box

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!