log.debug("Encoding page" + (getCurrentPageNumber() + 1));
renderParams = PNGEncodeParam.getDefaultEncodeParam(image);
OutputStream os = getCurrentOutputStream(getCurrentPageNumber());
if (os != null) {
try {
PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);
encoder.encode(image);
} finally {
//Only close self-created OutputStreams
if (os != firstOutputStream) {
IOUtils.closeQuietly(os);
}