RenderedImage image = (RenderedImage) getPageImage((PageViewport) pageViewportList
.get(i));
// Encode this image
log.debug("Encoding page " + (i + 1));
ImageWriterParams params = new ImageWriterParams();
params.setResolution(Math.round(userAgent.getTargetResolution()));
// Encode PNG image
ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(getMimeType());
log.debug("Writing image using " + writer.getClass().getName());
writer.writeImage(image, os, params);