atom feed1 message in org.apache.pdfbox.devImage Extraction width/height
FromSent OnAttachments
Christoph MäschigDec 16, 2009 5:20 pm 
Subject:Image Extraction width/height
From:Christoph Mäschig (chri@nerdindustries.com)
Date:Dec 16, 2009 5:20:54 pm
List:org.apache.pdfbox.dev

Hi!

I encountered a strange problem. I used PrintImageLocations.java as source for
my image extraction function, which is supposed to extract the image and it's position as well as it's width
and height in the PDF source document.

Everything works fine except the calculation of width and height.

I use the following code:

PDXObjectImage image = (PDXObjectImage) xobject; PDPage page = getCurrentPage(); Matrix ctm = getGraphicsState() .getCurrentTransformationMatrix(); double rotationInRadians = (page.findRotation() * Math.PI) / 180;

AffineTransform rotation = new AffineTransform(); rotation.setToRotation(rotationInRadians); AffineTransform rotationInverse = rotation.createInverse(); Matrix rotationInverseMatrix = new Matrix(); rotationInverseMatrix .setFromAffineTransform(rotationInverse); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(rotation);

Matrix unrotatedCTM = ctm.multiply(rotationInverseMatrix); float xScale = unrotatedCTM.getXScale(); float yScale = unrotatedCTM.getYScale();

float img_width = xScale / 100f * image.getWidth(); float img_height = yScale / 100f * image.getHeight();

But for some reason, the calculated Width and height are not correct, the
scaling factor is somehow strange and xScale and yScale differ, even when the image is scale proportional.

Does anybody know what I've to do?

Thanks a lot in advance! Chris