【问题标题】:iText: Cell with Image doesn't apply RowspaniText:带图像的单元格不适用 Rowspan
【发布时间】:2017-02-26 21:52:05
【问题描述】:

我有一张桌子 (2 x 2)。 如果我在行跨度为 2 的第一个单元格中添加一个短语作为单元格,它就可以工作。但是,如果我使用图像作为单元格,则行跨度永远不会适用。

    float[] rowwidths2 = {0.6f,0.4f};
    PdfPTable felsoegyharmad = new PdfPTable(rowwidths2);
    felsoegyharmad.setWidthPercentage(100);
    PdfPCell kepcell = new PdfPCell(new Phrase("image place", fontAlap));
    kepcell.setRowspan(2);
    felsoegyharmad.addCell(kepcell);
    felsoegyharmad.addCell(new Phrase("1", fontAlap));
    felsoegyharmad.addCell(new Phrase("2", fontAlap));

上面的代码是作为广告工作的。 但是下面的这段代码永远不会跨行:

    PdfPCell kepcell = new PdfPCell();
    kepcell.addElement(Image.getInstance(path));
    kepcell.setRowspan(2);
    felsoegyharmad.addCell(kepcell);
    felsoegyharmad.addCell(new Phrase("1", fontAlap));
    felsoegyharmad.addCell(new Phrase("2", fontAlap));

如何将此图像放入第一列但高度为两行?

【问题讨论】:

    标签: java image html-table itext


    【解决方案1】:

    如果您想知道为什么没有人回答您的问题。这很简单:您描述的问题无法重现。我采用了您的代码 sn-p,并创建了以下独立示例:

    PdfPTable table = new PdfPTable(2);
    PdfPCell imageCell = new PdfPCell();
    imageCell.addElement(Image.getInstance(IMG));
    imageCell.setRowspan(2);
    table.addCell(imageCell);
    table.addCell(new Phrase("1"));
    table.addCell(new Phrase("2"));
    

    完整源代码见ImageRowspan

    生成的 PDF 如下所示:

    如您所见,表格有两列和两行。第一个单元格(带有图像的单元格)跨越两行。你可以从 git 仓库下载cmp_image_rowspan.pdf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 2015-09-10
      • 2012-11-20
      • 2013-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多