Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   RTF to PDF (http://www.mirthcorp.com/community/forums/showthread.php?t=7066)

TSmithTRA 05-16-2012 12:43 PM

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 Packages.java.io.FileInputStream(inputfile);
var outputstream = new Packages.java.io.FileOutputStream(outputfile);

// Create an iText document
var myDocument = new Packages.com.lowagie.text.Document();

// Create a PDF writer object which we'll use to save the PDF in a moment
var pdfwriter = new Packages.com.lowagie.text.pdf.PdfWriter.getInstanc e(myDocument, outputstream);

// Open the iText document we created a moment ago so we can modify it
myDocument.open();

// Create a parser which will load the RTF file in a moment
var parser = new Packages.com.lowagie.text.rtf.parser.RtfParser(nul 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!
myDocument.close();

// Remove the temporary RTF file
var tidyUp = new Packages.java.io.File(inputfile);
tidyUp["delete"]();
__________________

cory_cole 05-17-2012 11:26 AM

var parser = new com.lowagie.text.rtf.direct.RtfParser();

bbeverage 05-27-2012 12:56 AM

Even using var parser = new com.lowagie.text.rtf.direct.RtfParser();

I get the following error:

Thanks for any help,
Brian

Code:

[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 com.lowagie.text.rtf.direct.RtfParser@e5922. (6ed92073-4883-4ad9-9ce6-cecacd41fda2#1437)
java.lang.Exception: org.mozilla.javascript.EcmaError: TypeError: Cannot find function convertRtfDocument in object com.lowagie.text.rtf.direct.RtfParser@e5922. (6ed92073-4883-4ad9-9ce6-cecacd41fda2#1437)
        at com.mirth.connect.connectors.js.JavaScriptMessageDispatcher.doDispatch(JavaScriptMessageDispatcher.java:96)
        at com.mirth.connect.connectors.js.JavaScriptMessageDispatcher.doSend(JavaScriptMessageDispatcher.java:103)
        at org.mule.providers.AbstractMessageDispatcher.send(AbstractMessageDispatcher.java:164)
        at org.mule.impl.MuleSession.sendEvent(MuleSession.java:191)
        at org.mule.impl.MuleSession.sendEvent(MuleSession.java:130)
        at org.mule.routing.outbound.AbstractOutboundRouter.send(AbstractOutboundRouter.java:85)
        at org.mule.routing.outbound.FilteringMulticastingRouter.route(FilteringMulticastingRouter.java:54)
        at org.mule.routing.outbound.OutboundMessageRouter$1.doInTransaction(OutboundMessageRouter.java:78)
        at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:48)
        at org.mule.routing.outbound.OutboundMessageRouter.route(OutboundMessageRouter.java:82)
        at org.mule.impl.model.DefaultMuleProxy.onCall(DefaultMuleProxy.java:247)
        at org.mule.impl.model.seda.SedaComponent.doSend(SedaComponent.java:209)
        at org.mule.impl.model.AbstractComponent.sendEvent(AbstractComponent.java:277)
        at org.mule.impl.MuleSession.sendEvent(MuleSession.java:201)
        at org.mule.routing.inbound.InboundMessageRouter.send(InboundMessageRouter.java:176)
        at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:143)
        at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487)
        at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266)
        at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:225)
        at com.mirth.connect.connectors.vm.VMMessageReceiver.getMessages(VMMessageReceiver.java:223)
        at org.mule.providers.TransactedPollingMessageReceiver.poll(TransactedPollingMessageReceiver.java:108)
        at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:97)
        at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
        at java.lang.Thread.run(Thread.java:662)Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function convertRtfDocument in object com.lowagie.text.rtf.direct.RtfParser@e5922. (6ed92073-4883-4ad9-9ce6-cecacd41fda2#1437)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3753)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3731)
        at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3759)
        at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3778)
        at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3842)
        at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2343)
        at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2310)
        at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1515)
        at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:845)
        at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3157)
        at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
        at com.mirth.connect.connectors.js.JavaScriptMessageDispatcher.doDispatch(JavaScriptMessageDispatcher.java:75)
        ... 25 more


AlexToft 05-27-2012 09:42 AM

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.

http://artofsolving.com/opensource/jodconverter

bbeverage 05-27-2012 10:01 AM

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?

Thanks,
Brian

AlexToft 05-27-2012 02:36 PM

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/DocumentConverter.py /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.

bbeverage 05-27-2012 04:54 PM

Thanks I would really appreciate the java channel version.

Thanks again,
Brian


All times are GMT -8. The time now is 11:16 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation