2

我在使用表格在 iTextSharp 中创建特定布局时遇到问题。

我首先创建一个表格,将页面一分为二,然后在每一列中插入一个额外的表格,每个表格有 x 行和 1 列。

我想这样做的原因是因为我想要一个类似于这个 HTML的布局。

但正在发生的事情如下:

在此处输入图像描述

根据代码独立的表似乎链接在一起。

旧代码

private void AddBody()
    {
        Image smallerLogo = Image.GetInstance(_logo);
        smallerLogo.ScaleAbsolute(100f, 100f);

        Image normalLogo = Image.GetInstance(_logo);

        ExtendedTable table = new ExtendedTable(2, 1, true, false, true);
        table.SetWidths(new[] { 50, 50 });

        ExtendedTable col1 = new ExtendedTable(1, 6, true, false, false);
        col1.AddCell(new ExtendedCell(new Chunk("Impressions", _headingFont), false));
        col1.AddCell(new ExtendedCell(smallerLogo, false));
        col1.AddCell(new ExtendedCell(new Chunk("Visitor funnel", _headingFont), false));
        col1.AddCell(new ExtendedCell(smallerLogo, false));
        col1.AddCell(new ExtendedCell(new Chunk("Shortlists", _headingFont), false));
        col1.AddCell(new ExtendedCell(smallerLogo, false));

        ExtendedTable col2 = new ExtendedTable(1, 6, true, false, false);
        col2.AddCell(new ExtendedCell(new Chunk("Leads", _headingFont), false));
        col2.AddCell(new ExtendedCell(normalLogo, false));
        col2.AddCell(new ExtendedCell(new Chunk("Demographics", _headingFont), false));
        col2.AddCell(new ExtendedCell(normalLogo, false));

        table.AddCell(new ExtendedCell(col1, false));
        table.AddCell(new ExtendedCell(col2, false));

        _document.Add(table);
    }

新代码

private void AddBody()
    {
        Image smallerLogo = Image.GetInstance(_logo);
        smallerLogo.ScaleAbsolute(60.0f, 60.0f);

        Image normalLogo = Image.GetInstance(_logo);

        PdfPTable table = new PdfPTable(2);
        table.SetWidths(new[] { 50, 50 });

        PdfPTable col1 = new PdfPTable(1);
        col1.AddCell("Impressions");
        col1.AddCell(new PdfPCell(smallerLogo));
        col1.AddCell("Visitor funnel");
        col1.AddCell(new PdfPCell(smallerLogo));
        col1.AddCell("Shortlists");
        col1.AddCell(new PdfPCell(smallerLogo));

        PdfPTable col2 = new PdfPTable(1);
        col2.AddCell("Leads");
        col2.AddCell(normalLogo);
        col2.AddCell("Demographics");
        col2.AddCell(normalLogo);

        table.AddCell(col1);
        table.AddCell(col2);

        _document.Add(table);
    }

WhereExtendedCellExtendedTable是删除表格边框的小类。

有任何想法吗?

4

0 回答 0