I am using the below function
public void renderImage(ImageRenderInfo renderInfo) {
try {
String filename;
FileOutputStream os;
PdfImageObject image = renderInfo.getImage();
PdfDictionary imageDict = renderInfo.getImage().getDictionary();
float widthPx = imageDict.getAsNumber(PdfName.WIDTH).floatValue();
float heightPx = imageDict.getAsNumber(PdfName.HEIGHT).floatValue();
float widthUu = renderInfo.getImageCTM().get(Matrix.I11);
float heigthUu = renderInfo.getImageCTM().get(Matrix.I22);
//while printing in inches I am dividing heightUu and widthUu by 72
System.out.printf("Image %.0fpx*%.0fpx, %.0fuu*%.0fuu, %.2fin*%.2fin\n", widthPx, heightPx, widthUu, heigthUu, widthUu/72, heigthUu/72);
if (image == null) return;
filename = String.format(path, renderInfo.getRef().getNumber(), image.getFileType());
System.out.println(filename);
os = new FileOutputStream(filename);
os.write(image.getImageAsBytes());
os.flush();
os.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
When I check the image sizes in photoshop, I am getting the height and width in pixels Perfectly, but not getting the width and height in Inches correctly.
I need it so that I can calculate the DPI of the image.
For Ex:
Image Original Values: width - 450 px and height - 362px
Width - 6.25 inches and height - 5.028 inches(Values got from photoshop)
What I recieve from itext:
width - 450 px and height - 362px (This is perfect)
Width -3.60 inches and height - 2.90 inches(Here is the problem)