web stats
Converting PDF File to an Encoded Base64 "Blob" - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2009, 06:42 AM
bdilworth bdilworth is offline
OBX.2 Kenobi
 
Join Date: Aug 2006
Location: Toledo, Ohio USA
Posts: 79
bdilworth
Unhappy Converting PDF File to an Encoded Base64 "Blob"

Hi All!

I am trying to coax Mirth to "read in" a PDF document file, convert the document to a Base64 encloded blob, and insert said Base64 encoded blob into OBX-5 of an ORU message. Inserting the Base64 encoded blob into OBX-5 of an ORU message is not a problem. I'm stuck at reading the PDF doc into Mirth and doing the Base64 encoding on the PDF doc.

First Question: How does one configure Mirth to read in a PDF file? There's a source connector option for File Reader, but the Incoming Data drop down box on the Summary tab includes options only for HL7 v2.X, HL7 v3.0, X12, EDI, XML, NCPDP, DICOM, and Delimited Text. Which one do you use to read in a PDF file?

Second Question: Once the PDF file is read into Mirth how does one Base64 encode it? The built-in FileUtil.encode(data) function seems to do only a byte at a time. I've found references here on the Forum for another function called Packages.com.webreach.mirth.util.Encrypter.encode([File content]) but when I try and use that I receive an error message that the "encode" method is not part of com.webreach.mirth.util.Encrypter.

So ... If anyone out there has successfully read in a PDF file and encoded it to a Base64 "blob" I'd love to see some code samples and/or pointers in the right direction.

Thanks in Advance!!!!!

Bob Dilworth
University of Toledo Medical Center
Toledo, Ohio
Reply With Quote
  #2  
Old 12-21-2009, 04:16 PM
WRyanH WRyanH is offline
What's HL7?
 
Join Date: May 2007
Posts: 1
WRyanH
Talking

Sorry Bob. I can give you code that does that in Ensemble but I haven't gotten to that point in Mirth yet.





Ryan Hulslander
Systems Integrator
Cedars-Sinai Health System
Los Angeles, CA

Last edited by WRyanH; 12-21-2009 at 04:17 PM. Reason: Updated name
Reply With Quote
  #3  
Old 12-29-2009, 07:11 PM
rwvaugha rwvaugha is offline
What's HL7?
 
Join Date: Dec 2009
Posts: 1
rwvaugha is on a distinguished road
Default

I am not sure how to read in a PDF file but I am able to base64 encode a zip file in my destination transformer.

I am passing in a byte array from a byte array output stream and then adding the encoded data to the channel map for use in the destination connector. I researched a bit to find out that a byte array must be passed into the encode function.

Code:
var encoded = FileUtil.encode(baos.toByteArray()); //Base64 encoded zipped output stream
channelMap.put('encodedZip', encoded);
Reply With Quote
  #4  
Old 01-07-2010, 07:27 AM
bdilworth bdilworth is offline
OBX.2 Kenobi
 
Join Date: Aug 2006
Location: Toledo, Ohio USA
Posts: 79
bdilworth
Default Converting PDF File to an Encoded Base64 "Blob"

Hmmm.

When I run the following javascript code:

var contents = FileUtil.readBytes("c:\temp\pdffile.pdf");
var b64Text = FileUtil.encode(contents.toByteArray());

I receive the following error:

Java class "[B" has no public instance field or method named "toByteArray".

If I run this code:

var contents = FileUtil.readBytes("c:\temp\pdffile.pdf");
var b64Text = FileUtil.encode(contents);

the variable b64Text contains the base64 encoded pdf document except that there's a <crlf> (i.e., 0d0a) between each line and when I convert it back to a pdf Acrobat pukes trying to read it. If I manually remove each of the <crlf> from the base64 encoded blob and convert it back to a pdf Abobe opens it just fine. :-(

Thoughts????

Bob D.
Toledo, Ohio
Reply With Quote
  #5  
Old 01-07-2010, 08:31 AM
josealmeida josealmeida is offline
OBX.1 Kenobi
 
Join Date: Dec 2009
Location: Portugal
Posts: 28
josealmeida is on a distinguished road
Default

Having the same problem. Just solved it about 1 hour ago:

http://www.mirthcorp.com/community/f...ead.php?t=3372

see the 4th post.
Reply With Quote
  #6  
Old 01-07-2010, 12:26 PM
bdilworth bdilworth is offline
OBX.2 Kenobi
 
Join Date: Aug 2006
Location: Toledo, Ohio USA
Posts: 79
bdilworth
Default

Quote:
Originally Posted by josealmeida View Post
Having the same problem. Just solved it about 1 hour ago:

http://www.mirthcorp.com/community/f...ead.php?t=3372

see the 4th post.
Unbelievably excellent!!!!!!!!!!!!!!!!!!!!! Thanks so much for posting this!!!!!!

Bob D.
Toledo, Ohio
USA
Reply With Quote
  #7  
Old 11-13-2012, 10:25 PM
praveenkathait praveenkathait is offline
Mirth Newb
 
Join Date: Jun 2008
Posts: 8
praveenkathait
Default :)Thanks a lot for the post

Hi All,

Thanks for the Post and guidance. I was dealing with the same issue from last 3 days. Have finally done it with the help of the code specified in the above post.

Thanks a lot everybody.

Amit Sharma
Reply With Quote
  #8  
Old 09-14-2016, 10:49 AM
lgiuriollo lgiuriollo is offline
Mirth Newb
 
Join Date: Sep 2016
Posts: 17
lgiuriollo is on a distinguished road
Default

Hi all,

i'm have a like problem:

i'm have a database(SQLServer), and this has a image field. This image field contains pdf files.

When i use the select in source in my channel, and triyng recovery the pdf file mirth return a message:

Transformer error
ERROR MESSAGE: Error evaluating transformer
com.mirth.connect.server.MirthJavascriptTransforme rException:
CHANNEL: PreventSenior
CONNECTOR: sourceConnector
SCRIPT SOURCE:
SOURCE CODE:
117:
118: channelMap.put('DESCRICAO', validate( mapping , '', new Array()));
119: var mapping;
120:
121: try {
122: mapping = msg['identificacaounica'].toString();
123: } catch (e) {
124: logger.error(e);
125: mapping = '';
126: }
LINE NUMBER: 122
DETAILS: TypeError: Character reference "�" is an invalid XML character.
at afa2c55b-39e5-4cbb-b763-dd17c8dffe02:44 (doScript)
at afa2c55b-39e5-4cbb-b763-dd17c8dffe02:162
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.call(JavaScr iptFilterTransformer.java:154)
at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.call(JavaScr iptFilterTransformer.java:119)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)



Someone has a solution to recover this file?

Thanks,
Leandro Giuriollo

Last edited by lgiuriollo; 09-19-2016 at 05:24 AM.
Reply With Quote
  #9  
Old 08-07-2017, 11:53 PM
m94 m94 is offline
What's HL7?
 
Join Date: Aug 2017
Posts: 1
m94 is on a distinguished road
Default Ensemble encode Base64 PDF

Quote:
Originally Posted by WRyanH View Post
Sorry Bob. I can give you code that does that in Ensemble but I haven't gotten to that point in Mirth yet.




Ryan Hulslander
Systems Integrator
Cedars-Sinai Health System
Los Angeles, CA
i know it is a long long, shot, but could you possibly share your Ensemble build to encode PDF as base64? I'm trying to accomplish that now
Reply With Quote
Reply

Tags
pdf base64 encode

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 01:05 AM.


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