itextsharp and images sizes

后端 未结 1 1533
北恋
北恋 2020-12-19 09:16

I am creating a single pdf page with 6 images in a table in separate cells, even though I am setting the images height and width on the server side exactly the same with Sca

相关标签:
1条回答
  • 2020-12-19 09:35

    Two things.

    First, see this post about wrapping the Image in a Chunk. Basically:

    iTextSharp.text.pdf.PdfPCell imgCell1 = new iTextSharp.text.pdf.PdfPCell();
    imgCell1.AddElement(new Chunk(img1, 0, 0));
    

    Second, if you want the exact same size then you want to use ScaleAbsolute instead of ScaleToFit. The latter keeps the aspect ratio of the image so a 100x200 image scaled to fit 50x50 would come out as 25x50.

    img1.ScaleAbsolute(120f, 155.25f);
    
    0 讨论(0)
提交回复
热议问题