Announcement

Collapse
No announcement yet.

Converting PDF File to an Encoded Base64 "Blob"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Bob Dilworth
    University of Toledo Medical Center
    Toledo, Ohio

  • #2
    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, 03:17 PM. Reason: Updated name

    Comment


    • #3
      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);

      Comment


      • #4
        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
        Bob Dilworth
        University of Toledo Medical Center
        Toledo, Ohio

        Comment


        • #5
          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.

          Comment


          • #6
            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
            Bob Dilworth
            University of Toledo Medical Center
            Toledo, Ohio

            Comment


            • #7
              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

              Comment


              • #8
                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, 04:24 AM.

                Comment


                • #9
                  Ensemble encode Base64 PDF

                  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

                  Comment

                  Working...
                  X