表格单元格中的大表调用分页符 [英] Large table in table cell invoke page break

查看:141
本文介绍了表格单元格中的大表调用分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PdfPTable和一列。一页适合50行。如果我向表中添加一些文本数据(例如,300行),报告工作正常。当我将PdfPTable添加到单元格中时(例如,20个字符串单元格,PdfPTable(其中包含20行或更少)和270个字符串单元格),所有工作都可以正常工作:

  / -------- 
20个字符串行
内部表(20行)
10个字符串行
/ - ------
...额外的行

但是,当我的内心表有更多行(mainTable [20个字符串行,innerTable [90个字符串行],270个字符串行],报告中断第一页,并在第二页上启动innerTable输出。

  / --------- 
20行字符串
30行空格
/ ---------
内表(90行中的50行)
/ ---------
内表(90行中的40行)
..附加数据

我需要这个:

  / --------- 
20个字符串行
内表(90行30行)
/ ---------
内表(90行50行)
/ ---------
内表(80行10行)
..附加数据

有人知道解决方案吗?



ps itext version - 2.1.7

解决方案

请查看


I have one PdfPTable with one column. One page fit 50 rows. If I add some text data to table (for an example, 300 rows), report work fine. When I add a PdfPTable into cell (for example, 20 string cells, PdfPTable(with 20 rows in it or less), and 270 string cells), all work fine too:

/--------
20 string rows
inner table (20 rows)
10 string rows
/-------
...additional rows

But, when my inner table have more rows (mainTable[20 string rows, innerTable[90 string rows], 270 string rows], report break first page, and start innerTable output on the second page.

/---------
20 string rows
whitespace for 30 rows
/---------
inner table (50 rows from 90)
/---------
inner table (40 rows from 90)
..additional data

And I need this:

/---------
20 string rows
inner table (30 rows from 90)
/---------
inner table (50 rows from 90)
/---------
inner table (10 rows from 80)
..additional data

Anybody know solution?

ps itext version - 2.1.7

解决方案

Please take a look at the NestedTables2 example. In this example, we tell iText that it's OK to split cells as soon as a row doesn't fit on a page:

This is not the default: by default, iText will try to keep a row intact by forwarding it to the next page. Only if the row doesn't fit the page, the row will be split.

Changing the default involves adding a single line to your code. That line is called: table.setSplitLate(false);

This is the full method that created the PDF shown in the screen shot:

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    PdfPTable table = new PdfPTable(2);
    table.setSplitLate(false);
    table.setWidths(new int[]{1, 15});
    for (int i = 1; i <= 20; i++) {
        table.addCell(String.valueOf(i));
        table.addCell("It is not smart to use iText 2.1.7!");
    }
    PdfPTable innertable = new PdfPTable(2);
    innertable.setWidths(new int[]{1, 15});
    for (int i = 0; i < 90; i++) {
        innertable.addCell(String.valueOf(i + 1));
        innertable.addCell("Upgrade if you're a professional developer!");
    }
    table.addCell("21");
    table.addCell(innertable);
    for (int i = 22; i <= 40; i++) {
        table.addCell(String.valueOf(i));
        table.addCell("It is not smart to use iText 2.1.7!");
    }
    document.add(table);
    document.close();
}

Note that you should not use iText 2.1.7. If you do, you could have a problem with your employer, customer, investor. Read more about this in the legal section of the free ebook The Best iText Questions on StackOverflow

这篇关于表格单元格中的大表调用分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆