【问题标题】:Table NoWrap Option in iText 7?iText 7中的Table NoWrap选项?
【发布时间】:2021-06-03 17:08:58
【问题描述】:

我正在将 iText5 代码转换为 iText7。我们使用的属性之一是我们的某些单元格上的 NoWrap (= true)。什么是 iText 7 等价物?谢谢!

new PdfPCell { NoWrap = true, ... }

【问题讨论】:

  • 请附上您的 iText 5 代码和您想要实现的视觉结果,以及到目前为止您使用 iText 7 尝试过的效果
  • 代码只是 new PdfPCell { NoWrap = true, ... }。只是寻找这个属性的等价物。
  • 效果,顾名思义,就是如果文本/内容的大小超过单元格的宽度,则没有换行。它只会溢出单元格的边界。

标签: itext itext7


【解决方案1】:

可以使用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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多