提问者:小点点

itextpdf: PdfPTable不需要高度


我将我的发布器核心从itext-2……迁移到itextpdf-5.5.6

在itext-2中,我在PdfPTable的单元格中添加了一个图像,我的表的celle与该图像大小相同。现在,在itextpdf-5.5.6中,图像的大小与该单元格一样小。

例如我使用

table.setTotalWidth(450);

在core itextpdf中,它也计算高度:

//ITEXTPDF
calculateWidths();
calculateHeights();

调用getRowHeight

getRowHeight(k, true);

它不做相同的,在itext-2:

  • itext返回400
  • itextpdf返回23

我对itextpdf进行了反编译,发现在pdfLine. getMaxSize(…)中有以下代码:

if (chunk.isImage()) {
  Image img = chunk.getImage();
  if (chunk.changeLeading()) {
    float height = chunk.getImageHeight() + chunk.getImageOffsetY() + img.getSpacingBefore();
    image_leading = Math.max(height, image_leading);
    }
  }

在itext的情况下,我没有这样的条件:

if (chunk.changeLeading()){......}

有解决它的平均值吗?


共1个答案

匿名用户

我发现问题在哪里:

Paragraph para = new Paragraph(new Chunk((Image) element, 0, 0, Boolean.FALSE));

chunk的最后一个参数是changeleader,它只需要更改为Boolean. TRUE

谢谢大家的回复