itextsharp在页面上生成三列两行的表

时间:2010-07-10 19:50:35

标签: c# itextsharp

希望它看起来像这样。然后我计划在每个表中放置条形码。任何帮助表示赞赏。

_________  ________  ______  
|       |  |      | |      |
|       |  |      | |      |
|       |  |      | |      | 
|       |  |      | |      |
---------  -------- --------
_________  ________  ______  
|       |  |      | |      |
|       |  |      | |      |
|       |  |      | |      | 
|       |  |      | |      |
---------  -------- --------

1 个答案:

答案 0 :(得分:0)

希望以下代码有用......

Document document = new Document(rect, marginLeft, marginRight, marginTop, marginBottom);

int tableColumns = 3;
Table aTable = new Table(tableColumns);
int row = 1;
int col = 0;
foreach (Barcode s in codeslist)
{
    // Create new barcode
    Image imageCode128 = GetImageCode128(s);

    // Create a new cell to host the barcode image
    Cell cell = new Cell();
    cell.Add(imageCode128);
    aTable.AddCell(cell,row,col);
    if (col == tableColumns-1)
    {
        col = 0;
        row ++;
    }
    else col++;
}

// Add the completed table to the Document and close it.
document.Add(aTable);

document.Close();