int imageHeight = awtImage.getHeight();
double pageHeight = drawer.getPageSize().getHeight();
LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
float yScaling = ctm.getYScale();
float angle = (float)Math.acos(ctm.getValue(0, 0)/ctm.getXScale());
if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0)
{
angle = (-1)*angle;
}
ctm.setValue(2, 1, (float)(pageHeight - ctm.getYPosition() - Math.cos(angle)*yScaling));
ctm.setValue(2, 0, (float)(ctm.getXPosition() - Math.sin(angle)*yScaling));
// because of the moved 0,0-reference, we have to shear in the opposite direction
ctm.setValue(0, 1, (-1)*ctm.getValue(0, 1));
ctm.setValue(1, 0, (-1)*ctm.getValue(1, 0));
AffineTransform ctmAT = ctm.createAffineTransform();
ctmAT.scale(1f/imageWidth, 1f/imageHeight);
drawer.drawImage( awtImage, ctmAT );
}
catch( Exception e )
{
LOG.error(e, e);
}
}
else if(xobject instanceof PDXObjectForm)
{
// save the graphics state
context.getGraphicsStack().push( (PDGraphicsState)context.getGraphicsState().clone() );
PDXObjectForm form = (PDXObjectForm)xobject;
COSStream formContentstream = form.getCOSStream();
// find some optional resources, instead of using the current resources
PDResources pdResources = form.getResources();
// 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, formContentstream );
// restore the graphics state