gpt4 book ai didi

java - iText:带有图像的单元格不适用 Rowspan

转载 作者:行者123 更新时间:2023-12-01 08:50:15 26 4
gpt4 key购买 nike

我有一张 table (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));

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

最佳答案

如果您想知道为什么没有人回答您的问题。很简单:您所描述的问题无法重现。我已经获取了您的代码片段,并创建了以下独立示例:

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 如下所示:

enter image description here

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

关于java - iText:带有图像的单元格不适用 Rowspan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42440133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com