关于c#:iTextSharp pdfpTable在同一页面的两列中流动

iTextSharp pdfpTable flowing in two columns in same page

我正在使用iTextSharp PdfPTtable从数据库创建表。当表很长(很长,但只有3列)时,我设法使表流动(或继续)到下一个PDF页面。但我希望它们在同一页面的右侧(或列)继续。之后,它必须继续到下一页(左列,然后右列,依此类推...)。
This


您的要求(几乎)与我的书中的一个例子完全匹配。
请查看column_table.pdf的第3页及更高版本。

该书具有示例的Java版本,但也有一个移植到C#的版本。

基本上,只要列中包含内容,就需要将PdfPTable添加到ColumnText对象和go()中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Column definition
float[][] x = {
    new float[] { document.Left, document.Left + 380 },
    new float[] { document.Right - 380, document.Right }
};
column.AddElement(yourTable);
int count = 0; // can be 0 or 1 if your page is divided in 2 parts
float height = 0;
int status = 0;
// render the column as long as it has content
while (ColumnText.HasMoreText(status)) {
    // add the top-level header to each new page
    if (count == 0) {
         AddFooterTable(); // for you to implement to add a footer
         height = AddHeaderTable(); // for you to implement to add a header
    }
    // set the dimensions of the current column
    column.SetSimpleColumn(
        x[count][0], document.Bottom,
        x[count][1], document.Top - height - 10
    );
    // render as much content as possible
    status = column.Go();
    // go to a new page if you've reached the last column
    if (++count > 1) {
        count = 0;
        document.NewPage();
    }
}
document.NewPage();