web stats
Mirth Community - View Single Post - RTF to PDF
Thread: RTF to PDF
View Single Post
  #1  
Old 05-16-2012, 11:43 AM
TSmithTRA TSmithTRA is offline
OBX.2 Kenobi
 
Join Date: Nov 2009
Location: Winston-Salem, NC
Posts: 79
TSmithTRA is on a distinguished road
Default 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"]();
__________________
__________________
Tom Smith
IT Director
Triad Radiology Associates
Reply With Quote