package com.qoppa.mule; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import org.mule.api.MuleMessage; import org.mule.api.transformer.TransformerException; import org.mule.transformer.AbstractMessageTransformer; import com.qoppa.pdf.PDFException; import com.qoppa.pdf.TIFFOptions; import com.qoppa.pdfImages.PDFImages; public class PDFToTIFF extends AbstractMessageTransformer { private final int DPI = 150; @Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { // Get the input stream InputStream inStream = (InputStream)message.getPayload(); try { // Load the PDF PDFImages pdf = new PDFImages(inStream, null); // Convert to TIFF ByteArrayOutputStream outStream = new ByteArrayOutputStream(); pdf.saveDocumentAsTIFF(outStream, new TIFFOptions(DPI, TIFFOptions.TIFF_PACKBITS)); // Return the TIFF in a byte array return outStream.toByteArray(); } catch (PDFException pdfE) { throw new TransformerException(this, pdfE); } catch (IOException ioe) { throw new TransformerException(this, ioe); } finally { try { inStream.close(); } catch(Throwable t) {} } } }