int imageHeight = image.getHeight();
double pageHeight = page.getMediaBox().getHeight();
System.out.println("*******************************************************************");
System.out.println("Found image [" + objectName.getName() + "]");
Matrix ctmNew = getGraphicsState().getCurrentTransformationMatrix();
float yScaling = ctmNew.getYScale();
float angle = (float)Math.acos(ctmNew.getValue(0, 0)/ctmNew.getXScale());
if (ctmNew.getValue(0, 1) < 0 && ctmNew.getValue(1, 0) > 0)
{
angle = (-1)*angle;
}
ctmNew.setValue(2, 1, (float)(pageHeight - ctmNew.getYPosition() - Math.cos(angle)*yScaling));
ctmNew.setValue(2, 0, (float)(ctmNew.getXPosition() - Math.sin(angle)*yScaling));
// because of the moved 0,0-reference, we have to shear in the opposite direction
ctmNew.setValue(0, 1, (-1)*ctmNew.getValue(0, 1));
ctmNew.setValue(1, 0, (-1)*ctmNew.getValue(1, 0));
AffineTransform ctmAT = ctmNew.createAffineTransform();
ctmAT.scale(1f/imageWidth, 1f/imageHeight);
float imageXScale = ctmNew.getXScale();
float imageYScale = ctmNew.getYScale();
System.out.println("position = " + ctmNew.getXPosition() + ", " + ctmNew.getYPosition());
// size in pixel
System.out.println("size = " + imageWidth + "px, " + imageHeight + "px");
// size in page units
System.out.println("size = " + imageXScale + ", " + imageYScale);
// 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.println();
}
else if(xobject instanceof PDXObjectForm)
{
// save the graphics state
getGraphicsStack().push( (PDGraphicsState)getGraphicsState().clone() );
PDPage page = getCurrentPage();
PDXObjectForm form = (PDXObjectForm)xobject;
COSStream invoke = (COSStream)form.getCOSObject();
PDResources pdResources = form.getResources();
if(pdResources == null)
{
pdResources = page.findResources();
}
// if there is an optional form matrix, we have to
// map the form space to the user space
Matrix matrix = form.getMatrix();
if (matrix != null)
{
Matrix xobjectCTM = matrix.multiply( getGraphicsState().getCurrentTransformationMatrix());
getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
}
processSubStream( page, pdResources, invoke );
// restore the graphics state