I am new to PDFBox and am stuck at finding the height of an image in inches. After a couple of searches, this is the piece of code that I am working with:
PDResources resources = aPdPage.findResources();
graphicsState = new PDGraphicsState(aPdPage.findCropBox());
pageWidth = aPdPage.findCropBox().getWidth() / 72;
pageHeight = aPdPage.findCropBox().getHeight() / 72;
@SuppressWarnings("deprecation")
Map<String, PDXObjectImage> imageObjects = resources.getImages();
if (null == imageObjects || imageObjects.isEmpty())
return;
for (Map.Entry<String, PDXObjectImage> entryxObjects : imageObjects.entrySet()) {
PDXObjectImage image = entryxObjects.getValue();
// System.out.println("bits per component: " + image.getBitsPerComponent());
Matrix ctmNew = graphicsState.getCurrentTransformationMatrix();
float imageXScale = ctmNew.getXScale();
float imageYScale = ctmNew.getYScale();
System.out.println("position = " + ctmNew.getXPosition() + ", " + ctmNew.getYPosition());
// size in pixel
System.out.println("size = " + image.getWidth() + "px, " + image.getHeight() + "px");
// size in page units
System.out.println("size = " + imageXScale + "pu, " + imageYScale + "pu");
// size in inches
imageXScale /= 72;
imageYScale /= 72;
System.out.println("size = " + imageXScale + "in, " + imageYScale + "in");
// size in millimeter
imageXScale *= 25.4;
imageYScale *= 25.4;
System.out.println("size = " + imageXScale + "mm, " + imageYScale + "mm");
System.out.printf("dpi = %.0f dpi (X), %.0f dpi (Y) %n", image.getWidth() * 72 / ctmNew.getXScale(), image.getHeight() * 72 / ctmNew.getYScale());
}
But the value is not coming correctly in inches. The imageXScale value in pu is coming to be 0.1 always.
Any help would be appreciated.