如何防止跨越多行的 iText 表 PdfPCell 跨页拆分?

发布于 2024-11-27 09:35:02 字数 219 浏览 4 评论 0原文

我正在使用 iText (iTextSharp 5.1.1),我正在尝试做一些表格。

第一个表列跨越几行。根据之前的内容,该专栏有时会分为两页。有时,第一页上只会保留一行,而该列的高度不足以显示标签。

有没有什么方法可以检测一列如果添加到文档中是否会跨越两页,以便我可以填写一些行来防止这种行为。

或者有没有办法告诉细胞在任何情况下不要分裂

I am using iText (iTextSharp 5.1.1) and I am trying to do some tables.

The first table column spans across several rows. Depending on previous content, the column would sometimes be split on two pages. Sometimes, only one row would remain on the first page, leaving the column not high enough for a label to be displayed.

Is there any way to detect if a column would span across two pages if added to a document, so I can fill in some rows to prevent this behavior.

Or is there a way to tell a cell not to split under any circumstances?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽心 2024-12-04 09:35:02

好吧,我用 Java 中的 iText 2.1.7 编写了您的示例:

PdfPTable table = new PdfPTable(2);
table.setSplitLate(true); // default value
PdfPCell largeCell =
        new PdfPCell(new Paragraph("Lorem ipsum dolor sit amet,\r\n"
                + "consectetur adipiscing elit. Curabitur\r\n"
                + "vel nisl quis turpis molestie blandit.\r\n"
                + "Donec a ligula sit amet quam feugiat\r\n"
                + "aliquet in id augue. Etiam placerat\r\n"
                + "massa ac ligula dictum convallis.\r\n"
                + "Mauris in leo quis lorem facilisis\r\n"
                + "tincidunt. Praesent lorem libero,\r\n"
                + "porttitor tincidunt egestas consequat,\r\n"
                + "tempor quis erat. Sed lorem ipsum,\r\n"
                + "posuere a ornare ac, viverra ut diam. In\r\n"
                + "porta ultrices tristique. Nulla non libero\r\n"
                + "a nisi pharetra consequat. Vestibulum\r\n"
                + "nunc urna, lobortis id ultricies vitae,\r\n"
                + "fermentum eu magna. Duis nibh lacus,\r\n"
                + "adipiscing at tempor eget, interdum\r\n" + "quis libero."));

PdfPCell cell = new PdfPCell(new Paragraph("Long Column"));
cell.setRowspan(5);
table.addCell(cell);
for (int i = 0; i < 5; i++)
{
    table.addCell(largeCell);
}

并且按照 Kornelije 的要求,它工作得很好...只有当我使用 table.setSplitLate(false) 时,才会产生“错误”输出。 code>,因此使用默认值 true 一切都很好。

Well, I coded your example with iText 2.1.7 in Java:

PdfPTable table = new PdfPTable(2);
table.setSplitLate(true); // default value
PdfPCell largeCell =
        new PdfPCell(new Paragraph("Lorem ipsum dolor sit amet,\r\n"
                + "consectetur adipiscing elit. Curabitur\r\n"
                + "vel nisl quis turpis molestie blandit.\r\n"
                + "Donec a ligula sit amet quam feugiat\r\n"
                + "aliquet in id augue. Etiam placerat\r\n"
                + "massa ac ligula dictum convallis.\r\n"
                + "Mauris in leo quis lorem facilisis\r\n"
                + "tincidunt. Praesent lorem libero,\r\n"
                + "porttitor tincidunt egestas consequat,\r\n"
                + "tempor quis erat. Sed lorem ipsum,\r\n"
                + "posuere a ornare ac, viverra ut diam. In\r\n"
                + "porta ultrices tristique. Nulla non libero\r\n"
                + "a nisi pharetra consequat. Vestibulum\r\n"
                + "nunc urna, lobortis id ultricies vitae,\r\n"
                + "fermentum eu magna. Duis nibh lacus,\r\n"
                + "adipiscing at tempor eget, interdum\r\n" + "quis libero."));

PdfPCell cell = new PdfPCell(new Paragraph("Long Column"));
cell.setRowspan(5);
table.addCell(cell);
for (int i = 0; i < 5; i++)
{
    table.addCell(largeCell);
}

And it works quite well as asked by Kornelije... The "wrong" output will only be produced, when I use table.setSplitLate(false), so with the default value of true everything is just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文