【问题标题】:iTextSharp pdfpTable flowing in two columns in same pageiTextSharp pdfpTable 在同一页面的两列中流动
【发布时间】:2015-04-27 18:52:51
【问题描述】:

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

【问题讨论】:

    标签: c# asp.net-mvc pdf-generation itextsharp pdfptable


    【解决方案1】:

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

    本书有示例的Java version,但也有version ported to 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();
    

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 2011-01-05
      • 1970-01-01
      • 2011-05-04
      • 2014-05-18
      • 2011-01-20
      • 2013-04-15
      • 2014-11-24
      • 1970-01-01
      相关资源
      最近更新 更多