Announcement

Collapse
No announcement yet.

send a pdf as response

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

  • send a pdf as response

    I wish to send back as channel response, a generated document.
    As seen around the forum, I created the pdf destination and using a postProcessor script I tried to send it back.
    Code:
    logger.info('http test- MID '+messageObject.getId());
    var contents = FileUtil.readBytes('/tmp/http-test/'+channelMap.get('MESSID')+'.pdf');
    var encData=FileUtil.encode(contents);
    var resp= 'application/pdf;base64,'+encData
    responseMap.put('pdf resp',  ResponseFactory.getSuccessResponse(resp));
    return;
    The result is I can see the base64 code, not the pdf file. Same thing using FileUtil.read() to read the pdf as a string and sending it as is, without encoding.
    Should Some suggest anything?
    Thank you.

  • #2
    Hi supertoms,

    Did you have any luck figuring this out? I'm having the same problem using version 1.8.1.4211

    Could it be that Mirth doesn't allow us to change the headers?

    Thanks!
    Last edited by csmith; 01-04-2010, 08:59 AM. Reason: more info

    Comment


    • #3
      Hi.
      I've tried without success.
      I can't control the mime type of returned file. The browser still handl it as text or html.
      I've also tried to included the returned object into an html page, selecting the correct mime type but without success.

      Comment


      • #4
        see the 4th post in this thread to see if it helps:

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

        I used a postProcessor javascript with that code.
        Last edited by josealmeida; 01-07-2010, 07:39 AM.

        Comment


        • #5
          Thanks for suggestions, but the problem is still open.
          I've an http source that receive Response from "pdf resp", a responseMap value declared.
          My postprocess script is:
          Code:
          logger.info('http test- MID '+messageObject.getId());
          logger.info('file '+'/tmp/http-test/'+channelMap.get('MESSID')+'.pdf');
          var contents = FileUtil.readBytes('/tmp/http-test/'+channelMap.get('MESSID')+'.pdf');
          logger.info('encode');
          var encData=FileUtil.encode(contents);
          //remove the newlines to produce valid Base64
          var index = encData.indexOf("\r\n");
              while(index != -1){
                  encData = encData.replace("\r\n","");
                  index = encData.indexOf("\r\n");
              }
          var resp=encData;
          responseMap.put('pdf resp',  ResponseFactory.getSuccessResponse(resp));
          return;
          Obviouslly I've a destination channel who create a pdf.
          In this way, calling http://myserver:8083/?testType=httpTestMirth&value=56
          I can see the text data of my pdf on my browser. The returned page generated is a text/html page not pdf.

          Comment


          • #6
            supertoms: yes, the returned data is text since it is base64 encoded. Decode the data and you have your pdf document.
            Daniel Svanstedt
            Software Engineer
            Mirth Corporation

            Want professional services, support, and enterprise or virtual appliances? It's all available from the Mirth Corporation:
            Mirth Support | Mirth Training | Mirth Appliances | Online Training | Developer Q&A

            Don't forget, Mirth Support gives you access to all of our online training videos, and silver support gives you access to developer Q&As!

            Comment


            • #7
              Hi,

              I've been trying to develop a test channel which listens for an http request and returns a pdf to the client's browser.

              Here's what I have as a postprocessor script:
              ************************************************** **************************
              var contents = FileUtil.readBytes('/var/www/test.pdf');
              var encData=FileUtil.encode(contents);
              var index = encData.indexOf("\r\n");
              while(index != -1){
              encData = encData.replace("\r\n","");
              index = encData.indexOf("\r\n");
              }
              var resp=FileUtil.decode(encData);
              resp = 'application/pdf,' + resp;
              responseMap.put('pdf resp', ResponseFactory.getSuccessResponse(resp));
              return;
              ************************************************** ***********************************
              When I prompt the channel thusly http://xxxxxx:8111 (the port being configured
              in the Source), the expected pdf isn't returned, but, rather, a bunch of characters.
              No errors are logged by the server.

              I'm using MirthConnect version 1.8.1.4211

              Any insights would be hugely appreciated (as always)!

              Comment

              Working...
              X