Im using iTextPdf library, and I want to insert image from gallery into pdf in such a way that image width may be resized if its width is larger than document width, else keep its width as it is, (Similarly with the height) without affecting the aspect ratio of the actual image. In simple words, I don't want the image to be stretched.
I started using iTextPdf recently only and not so familiar with it.
I've tried using
image.scaleAbsolute()
image.scaleToFit()
image.scalePercent()
but none of these methods seem to solve my problem since image can have different width and height.
I've been looking for this answer for days but no luck.
I would be happy with any help. Thanks.
Asked
Active
Viewed 173 times
0

steady blaze
- 3
- 3
-
1https://stackoverflow.com/questions/11120775/itext-image-resize – PeterMmm Mar 29 '22 at 17:24
-
Please provide enough code so others can better understand or reproduce the problem. – Community Mar 30 '22 at 09:30
-
Thank you. Got the answer (answered by `Franz Ebner`) from link provided by @PeterMmm. This is the line that solved my problem: float scaler =((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin()) / image.getWidth()) * 100; image.scalePercent(scaler); – steady blaze Mar 31 '22 at 18:15