Hi Chris,
Gesendet: Do, 17. Dez 2009 Von: Christoph Mäschig<christ...@nerdindustries.com> > 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? The PrintImageLocations example is using some old code from the "Do"-operator. Have a look at the improved implementation at [1]. IMHO we should fix that example. BTW: the mentioned code is in the Invoke- and the BeginInlineImage-operator. Furthermore we have to use that code in the PrintImageLocations example, too. I think we should unify the code. > Thanks a lot in advance! > Chris BR Andreas Lehmkühler [1] http://svn.apache.org/repos/asf/pdfbox/trunk/src/main/java/org/apache/pdfbox/util/operator/pagedrawer/Invoke.java