我开发了一个程序,我创建了一个列并在该列中插入了一个段落。
ColumnText ct = new ColumnText(cb);
Font font = new Font(bfBold.createFont());
//float maxFontSize=10;
font.setSize(10);
Paragraph p = new Paragraph("This is a long paragraph that doesn't fit the width we defined for the simple column of the ColumnText object, so it will be distributed over several lines (and we don't know in advance how many).",font);
p.setAlignment(Element.ALIGN_JUSTIFIED);
//LineNumberReader lineNumberReader = new LineNumberReader(new StringReader());
ct.setSimpleColumn(100f, 550f, 395f, 150f);
ct.addElement(p);
ct.go();
我已将段落插入ct(column text)
。
所以现在我想计算这一段的内容。 那我怎么能这样做呢?
我使用了itext api。我在这里生成一个pdf。
答案 0 :(得分:1)
在呈现ColumnText
的内容之后(无论是真实模式还是模拟模式),您可以使用getLinesWritten()方法获取已写入的行数。
我使用的链接指向iText API文档。您还可以在常见问题解答中找到此信息:How to get the rendered dimensions of text?以及“iText in Action”一书中的示例;请参阅MovieColumns1示例。
我很抱歉“仅限链接”的答案(在StackOverflow上通常不受欢迎),但唯一需要的代码行是:
int lines = ct.getLinesWritten();