No announcement yet.


  • Filter
  • Time
  • Show
Clear All
new posts

  • RTF to PDF

    Has anyone had any luck using Mirth to convert an RTF document to PDF using the embedded iText libraries?

    I have code in place that "looks" like it should work but I get the following error.

    Any Help would be greatly appreciated.

    "DETAILS: TypeError: [JavaPackage com.lowagie.text.rtf.parser.RtfParser] is not a function, it is object."

    Transformer code is below

    // Pull the RTF from the OBX and unescape it...
    //var contents = $('ReportContent');
    var contents = $('RTFContentsString');
    //var pdfString = new String(Base64.decodeBase64(contents.toString()));
    var pdfString = org.apache.commons.codec.binary.Base64.decodeBase6 4(contents.toString());
    //var pdfString = new String(Base64.decodeBase64(contents.getBytes("asci i")));

    //contents = contents.replace(/\\E\\/g, "\\");
    //contents = contents.replace(/\\.br\\/g, "\r\n");
    //FileUtil.write('F:/tmp/input.rtf', false, contents);

    // Generate a unix time stamp for use as the output filename (we'll use something a little more robust for prod, but this is useful for test)
    var foo = new Date;
    var unixtime_ms = foo.getTime();
    var unixtime = parseInt(unixtime_ms / 1000);

    // Set the variables for the input file and output file
    var inputfile = "F:/tmp/input.rtf";
    var outputfile = "F:/output/"+unixtime+".pdf";

    // Create the respective streams for the files
    var inputstream = new;
    var outputstream = new;

    // Create an iText document
    var myDocument = new;

    // Create a PDF writer object which we'll use to save the PDF in a moment
    var pdfwriter = new e(myDocument, outputstream);

    // Open the iText document we created a moment ago so we can modify it;

    // Create a parser which will load the RTF file in a moment
    var parser = new l);

    // Parse the RTF input and pass it to the PDF writer object
    parser.convertRtfDocument(inputstream, myDocument);

    // Close the document and hopefully it will contain what we want!

    // Remove the temporary RTF file
    var tidyUp = new;
    Tom Smith
    IT Director
    Triad Radiology Associates

  • #2
    var parser = new;


    • #3
      Even using var parser = new;

      I get the following error:

      Thanks for any help,

      [2012-05-27 02:52:11,422]  ERROR (org.mule.impl.DefaultComponentExceptionStrategy:95): Caught exception in Exception Strategy for: 505b69da-6235-47ac-ad1a-74a074472081: java.lang.Exception: org.mozilla.javascript.EcmaError: TypeError: Cannot find function convertRtfDocument in object [email protected] (6ed92073-4883-4ad9-9ce6-cecacd41fda2#1437)
      java.lang.Exception: org.mozilla.javascript.EcmaError: TypeError: Cannot find function convertRtfDocument in object [email protected] (6ed92073-4883-4ad9-9ce6-cecacd41fda2#1437)
      	at com.mirth.connect.connectors.js.JavaScriptMessageDispatcher.doDispatch(
      	at com.mirth.connect.connectors.js.JavaScriptMessageDispatcher.doSend(
      	at org.mule.providers.AbstractMessageDispatcher.send(
      	at org.mule.impl.MuleSession.sendEvent(
      	at org.mule.impl.MuleSession.sendEvent(
      	at org.mule.routing.outbound.AbstractOutboundRouter.send(
      	at org.mule.routing.outbound.FilteringMulticastingRouter.route(
      	at org.mule.routing.outbound.OutboundMessageRouter$1.doInTransaction(
      	at org.mule.transaction.TransactionTemplate.execute(
      	at org.mule.routing.outbound.OutboundMessageRouter.route(
      	at org.mule.impl.model.DefaultMuleProxy.onCall(
      	at org.mule.impl.model.seda.SedaComponent.doSend(
      	at org.mule.impl.model.AbstractComponent.sendEvent(
      	at org.mule.impl.MuleSession.sendEvent(
      	at org.mule.routing.inbound.InboundMessageRouter.send(
      	at org.mule.routing.inbound.InboundMessageRouter.route(
      	at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(
      	at org.mule.providers.AbstractMessageReceiver.routeMessage(
      	at org.mule.providers.AbstractMessageReceiver.routeMessage(
      	at com.mirth.connect.connectors.vm.VMMessageReceiver.getMessages(
      	at org.mule.providers.TransactedPollingMessageReceiver.poll(
      	at by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function convertRtfDocument in object [email protected] (6ed92073-4883-4ad9-9ce6-cecacd41fda2#1437)
      	at org.mozilla.javascript.ScriptRuntime.constructError(
      	at org.mozilla.javascript.ScriptRuntime.constructError(
      	at org.mozilla.javascript.ScriptRuntime.typeError(
      	at org.mozilla.javascript.ScriptRuntime.typeError2(
      	at org.mozilla.javascript.ScriptRuntime.notFunctionError(
      	at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(
      	at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(
      	at org.mozilla.javascript.Interpreter.interpretLoop(
      	at org.mozilla.javascript.Interpreter.interpret(
      	at org.mozilla.javascript.ContextFactory.doTopCall(
      	at org.mozilla.javascript.ScriptRuntime.doTopCall(
      	at org.mozilla.javascript.InterpretedFunction.exec(
      	at com.mirth.connect.connectors.js.JavaScriptMessageDispatcher.doDispatch(
      	... 25 more


      • #4
        I had much more reliable results by running OpenOffice in headless mode and invoking JodConverter (as a custom jar) from a Mirth transformer to do rtf/pdf converts.


        • #5
          Thanks for the reply. I am new to mirth do you have an example of what you did?

          So I need to add JodConverter as a custom library to mirth and then can call it from within mirth?



          • #6
            You invoke OpenOffice like this (This is a Linux example as I don't work with Windows, but easy to adapt):

            /path/to/openoffice/program/soffice.bin -headless -nofirststartwizard -accept="socket,host=localhost,port=8100;urp;StarOf fice.Service"

            This is the command for the Python lib version of JobConverter:
            java.lang.Runtime.getRuntime().exec("/usr/bin/python /opt/scripts/ /opt/input/”+source+”.rtf”+” /opt/output/”+destination+”.pdf”;

            I then had another channel pick up the PDFs and send them to destination. Been about a year since I touched this, but will try and dig out the channel code for the Java version.


            • #7
              Thanks I would really appreciate the java channel version.

              Thanks again,