int imageHeight = awtImage.getHeight();
double pageHeight = drawer.getPageSize().getHeight();
log.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
int pageRotation = page.findRotation();
AffineTransform ctmAT = ctm.createAffineTransform();
ctmAT.scale(1f/imageWidth, 1f/imageHeight);
Matrix rotationMatrix = new Matrix();
rotationMatrix.setFromAffineTransform( ctmAT );
// calculate the inverse rotation angle
// scaleX = m00 = cos
// shearX = m01 = -sin
// tan = sin/cos
double angle = Math.atan(ctmAT.getShearX()/ctmAT.getScaleX());
Matrix translationMatrix = null;
if (pageRotation == 0 || pageRotation == 180)
{
translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getXScale()), (float)(pageHeight-2*ctm.getYPosition()-Math.cos(angle)*ctm.getYScale()));
}
else if (pageRotation == 90 || pageRotation == 270)
{
translationMatrix = Matrix.getTranslatingInstance((float)(Math.sin(angle)*ctm.getYScale()), (float)(pageHeight-2*ctm.getYPosition()));
}
rotationMatrix = rotationMatrix.multiply(translationMatrix);
rotationMatrix.setValue(0, 1, (-1)*rotationMatrix.getValue(0, 1));
rotationMatrix.setValue(1, 0, (-1)*rotationMatrix.getValue(1, 0));
AffineTransform at = new AffineTransform(
rotationMatrix.getValue(0,0),rotationMatrix.getValue(0,1),
rotationMatrix.getValue(1,0),rotationMatrix.getValue(1,1),
rotationMatrix.getValue(2,0),rotationMatrix.getValue(2,1)
);
drawer.drawImage( awtImage, at );
}
catch( Exception e )
{
e.printStackTrace();
log.error(e, e);
}
}
else if(xobject instanceof PDXObjectForm)
{
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( context.getGraphicsState().getCurrentTransformationMatrix());
context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM);
}
getContext().processSubStream( page, pdResources, invoke );
}
else