web stats
Help converting rtf document to plain text - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2013, 12:26 PM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default Help converting rtf document to plain text

Does anyone have any suggestions as to how I might be able to convert a RTF document that I am extracting from an Oracle database using .getClob() to plain text for the receiving system which cannot handle rtf format?
Reply With Quote
  #2  
Old 03-25-2013, 08:00 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Quote:
Originally Posted by seaston View Post
Does anyone have any suggestions as to how I might be able to convert a RTF document that I am extracting from an Oracle database using .getClob() to plain text for the receiving system which cannot handle rtf format?
Mirth Connect includes iText, so that may be your best bet. Though, you may also be able to just strip all RTF commands with a regular expression.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 03-27-2013, 01:40 AM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default

This is what I have done so far (part of a transformer step), using regular expressions:

Code:
var results = new XML("<results/>");
var result = dbConn.executeCachedQuery(query);

result.beforeFirst();

while (result.next()) {

	var attendance = new XML("<attendance/>");
	attendance["hospital_number"] = result.getString("hospital_number");
	attendance["attendance_number"] = result.getString("attendance_number");
	attendance["bookdate"] = result.getString("bookdate");
	attendance["exams"] = result.getString("exams");
	channelMap.put("report",result.getClob("reports"));
	var cl=result.getClob("reports");
	var strOut = new java.lang.StringBuffer();
	var aux = new java.lang.String();
	var br = new java.io.BufferedReader(cl.getCharacterStream());
	while ((aux = br.readLine())!= null)
		strOut.append(aux + "");
	channelMap.put('gDocTextString', strOut);

	// Using java.lang.String because javascript replace does not support negative lookbehind.
	// These regular expressions seem to be quite effective at stripping out all the RTF control sequences
	
	resultString = java.lang.String(strOut).replaceAll("(?s)\\\\(par|line)(?=(\W|\\w+\\s|\\s|[{}]))", "");
	resultString = java.lang.String(resultString).replaceAll("\\{\\*?\\\\[^{}]+\\}|\\\\(?=\\\\)|\\\\(?=[{}])|(?<!\\\\)[{}]|(?<!\\\\)\\\\[A-Za-z]+\n?(?:-?\\d+)?[ ]?", "");
	resultString = java.lang.String(resultString).replaceAll("", "\n");
	resultString = resultString.trim();
	channelMap.put("resultString",resultString);
	attendance["reports"] = resultString ;
	results[""] += attendance;
    }


dbConn.close();

channelMap.put("results",results);
tmp = results;

I could not work out how to use iText to convert the rtf format to plain text. If anyone can help me out with an alternative to the code above using iText it would be appreciated.
Reply With Quote
  #4  
Old 03-27-2013, 07:37 AM
sandersmr sandersmr is offline
OBX.2 Kenobi
 
Join Date: Feb 2013
Posts: 71
sandersmr is on a distinguished road
Default

Which version of iText does Mirth use? Versions 5.0.0 and up don't include RTF support (that's been pushed to a separate project).
Reply With Quote
  #5  
Old 03-27-2013, 10:32 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

Quote:
Originally Posted by sandersmr View Post
Which version of iText does Mirth use? Versions 5.0.0 and up don't include RTF support (that's been pushed to a separate project).
We're currently using version 2.0.8.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
Reply

Tags
convert, parse, plain, rtf, text

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 07:35 PM.


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