iTextSharp在到达页面末尾时自动收缩图像

iTextSharp在到达页面末尾时自动收缩图像,itext,Itext,我正在使用iTextSharp在pdf报告中显示图像。在这里,我想显示两个图像在一行,它的工作正如预期,但有一个问题时,页面的结尾达到。问题是最后一行图像会缩小以适应同一页面,而不会自动将其添加到下一页。具有相同尺寸和分辨率的所有图像 最简单的解决方案(考虑到所有图像都具有相同的尺寸和分辨率)是每次在页面中插入最大数量的图像时手动插入新页面和分页符。请向我们提供代码 我写了下面的测试(虽然是用java编写的,应该没有问题),结果似乎是正确的 public void tableWithIm

我正在使用iTextSharp在pdf报告中显示图像。在这里,我想显示两个图像在一行,它的工作正如预期,但有一个问题时,页面的结尾达到。问题是最后一行图像会缩小以适应同一页面,而不会自动将其添加到下一页。具有相同尺寸和分辨率的所有图像


最简单的解决方案(考虑到所有图像都具有相同的尺寸和分辨率)是每次在页面中插入最大数量的图像时手动插入新页面和分页符。

请向我们提供代码

我写了下面的测试(虽然是用java编写的,应该没有问题),结果似乎是正确的

    public void tableWithImagesTest01() throws IOException, InterruptedException {
    String testName = "tableWithImagesTest01.pdf";
    String outFileName = destinationFolder + testName;
    String cmpFileName = sourceFolder + "cmp_" + testName;

    PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName));
    Document doc = new Document(pdfDoc, PageSize.A3);

    Image image1 = new Image(ImageDataFactory.create(sourceFolder + "itis.jpg"));
    Table table = new Table(2);
    for (int i = 0; i < 20; i++) {
        table.addCell(new Cell().add(image1));
        table.addCell(new Cell().add(image1));
        table.addCell(new Cell().add(new Paragraph("Hello")));
        table.addCell(new Cell().add(new Paragraph("World")));
    }
    doc.add(table);

    doc.close();
    Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
}
public void tableWithImagesTest01()抛出IOException、InterruptedException{
String testName=“tableWithImagesTest01.pdf”;
字符串outFileName=destinationFolder+testName;
字符串cmpFileName=sourceFolder+“cmp_513;”+testName;
PdfDocument pdfDoc=新的PdfDocument(新的PdfWriter(outFileName));
文档文档=新文档(pdfDoc,PageSize.A3);
Image image1=新映像(ImageDataFactory.create(sourceFolder+“itis.jpg”);
表=新表(2);
对于(int i=0;i<20;i++){
table.addCell(新单元格().add(图像1));
table.addCell(新单元格().add(图像1));
table.addCell(newcell().add(新段落(“Hello”));
表.addCell(新单元格().add(新段落(“世界”));
}
单据新增(表);
doc.close();
Assert.assertNull(新的CompareTool().compareByContent(outFileName、cmpFileName、destinationFolder,“diff”);
}
结果pdf如下所示:


可能您使用summat
image1.setAutoScale(true)?我们仍然需要您的代码来查看

根据下面的评论,有效的解决方案是,对需要设置的单个图像:

image.ScaleToFitHeight=false


将行放在一起时可能会发生

您可能应该提供一些代码来重现您的问题。谢谢,我终于找到了解决这个问题的办法。image.ScaleToFitHeight=false;