iTextSharp pdfpTable在同一页面的两列中流动 [英] iTextSharp pdfpTable flowing in two columns in same page
问题描述
我正在使用iTextSharp PdfPTtable
从数据库创建表.当表很长(很长,但只有3列)时,我设法使表流动(或继续)到下一个PDF页面.但我希望它们在同一页面的右侧(或列)继续.之后,它必须继续到下一页(左列,然后右列,依此类推...).
I am using iTextSharp PdfPTtable
for creating tables from a database. When the table is lengthy (long but just with 3 columns), I managed to get the table flowing (or continuing) to the next PDF page. But I want them to continue in the right side (or column) of the same page. And after that it has to continue to next page (left column and then the right column and so on...).
推荐答案
您的要求(几乎)与我的书中的一个示例完全匹配. 请查看 column_table.pdf 的第3页及更高版本.
Your requirement is (almost) an exact match with one of the examples of my book. Please take a look at page 3 and higher of column_table.pdf.
这本书具有示例的 Java版本,但也有一个示例版本已移植到C#.
The book has the Java version of the example, but there's also a version ported to C#.
基本上,只要列中包含内容,就需要将PdfPTable
添加到ColumnText
对象和go()
:
Basically, you need to add the PdfPTable
to a ColumnText
object and go()
as long as there is content in the column:
// 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();
这篇关于iTextSharp pdfpTable在同一页面的两列中流动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!