2

データベースからテーブルを作成するために iTextSharp を使用PdfPTtableしています。表が長い (長いが 3 列しかない) 場合、表を次の PDF ページにフロー (または継続) させることができました。しかし、同じページの右側 (または列) に続けてほしいのです。その後、次のページに進む必要があります (左の列、次に右の列など...)。 これは、データベースからのデータが流れる方法です。

4

1 に答える 1

3

あなたの要件は、私の本の例の 1 つと (ほぼ) 正確に一致しています。column_table.pdfの 3 ページ目以降をご覧ください。

この本にはサンプルのJava バージョンがありますが、C# に移植されたバージョンもあります。

基本的に、列にコンテンツがある限りPdfPTableColumnTextオブジェクトに を追加する必要があります。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();
于 2015-02-25T23:39:50.067 に答える