[英]iTextSharp pdfpTable flowing in two columns in same page
我正在使用 iTextSharp PdfPTtable
從數據庫創建表。 當表格很長(很長但只有 3 列)時,我設法讓表格流動(或繼續)到下一個 PDF 頁面。 但我希望它們在同一頁面的右側(或列)繼續。 之后它必須繼續到下一頁(左欄,然后是右欄等等......)。
您的要求(幾乎)與我書中的一個示例完全匹配。 請查看column_table.pdf 的第 3 頁及更高版本。
這本書有該示例的Java 版本,但也有一個移植到 C#的版本。
基本上,只要列中有內容,您就需要將PdfPTable
添加到ColumnText
對象和go()
:
// 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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.