我正在将 iText5 代码转换为 iText7。我们在某些单元格上使用的属性之一是 NoWrap (= true)。什么是 iText 7 等价物?谢谢!
new PdfPCell { NoWrap = true, ... }
可以使用
Property.OVERFLOW_X
来控制内容的溢出策略。但它需要在包含内容的元素上设置,通常在段落上。
这里是一个代码示例,添加一个表格,其中的单元格包含不适合给定单元格宽度 (
100pt
) 的内容:
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
Document document = new Document(pdfDocument);
Table table = new Table(new float[] {100, 100, 100});
table.setFixedLayout();
table.setWidth(300);
table.addCell("Hello world");
Paragraph p = new Paragraph("ThisIsAVeryLongLongWordWhichOverflowsCellWidth").setFontColor(ColorConstants.GREEN);
table.addCell(p);
p.setProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
table.addCell("Last cell");
document.add(table);
document.close();
当文本中有空格时,此解决方案不起作用。空格显示为换行符。我如何使它出现在一个单元格中,并且 nowrap 为真。
This Very LongLongWordWhichOverflows CellWidth 谢谢。