Forum Discussion

Premier2k's avatar
Occasional Contributor
9 years ago

View a PDF in SOAPUI?

Hi all,


I'm quite new to SOAPUI and I've created a test that calls a service to return a receipt. The receipt is returned as a PDF. As far as I can tell we can't display that PDF in SOAPUI?


Currently I get back a lot of what seems to be encoded data. Is there a way for me to actually view the PDF or is this not possible? Below is a snapshot of the data I'm currently getting returned.

I'm currently using the free version of SOAP and not the Pro version.







HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 153285
Content-Type: application/pdf
Expires: -1
Server: Microsoft-IIS/8.5
ActivityId: a82ffe15-6405-4b2f-94a5-ad933c7deb22
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Mon, 13 Jul 2015 10:16:30 GMT

1 0 obj
/Title <5061796D656E742052656365697074203F2054656D706C6174652049443A204430
/Author <497265737320536F6C7574696F6E73>
/Keywords <>


8 Replies

  • Is this the entire response?


    I've seen cases where a PDF has been encoded in Base64 format (which will look like a bunch of letters and numbers). If that's the case, then that can be decoded in SoapUI Using the following groovy script:


    def groovyUtils = new context );
    import org.apache.commons.codec.binary.Base64;
    Base64 coder = new Base64();
    def timeInMilis = System.currentTimeMillis()
    def filename = context.expand( '/invoice' + timeInMilis +'.pdf')
    def encodedString = context.expand( '${#TestCase#base64Text}' );
    def decoded = encodedString.decodeBase64();
    def f = new File(groovyUtils.projectPath + filename);
    f << decoded
      + filename);

    Assuming you have a test case property called base64Text (where you've extracted and stored the encoded data) this code will decode the rest for you, and save it as a PDF file.

    • rupert_anderson's avatar
      Valued Contributor



      Where you say 'is this the entire response?' are you talking about the PDF response?


      BTW - I think you have provided something similar to the script for option 1) from my earlier post, although I think your script is assuming that the response contains a Base64 encoded copy of the PDF, which it doesn't in @Premier2k s original post - it is instead binary, as the Content-Type is shown as application/pdf. Still nice enough script, have some kudos :-)


      A Base64 encoded PDF might well be easier to deal with, I have done someting similar quite recently to get base64 from a webservice response and then stream it to a browser for display (not in SoapUI though). When dealing with application/pdf, I think it should be possible to stream the binary PDF data to a file in a similar way (perhaps using the iText library).. or somehow popup a browser (which has a pdf plugin) and redirect the PDF data there..






      • Nitika1's avatar
        New Member

        You can not view PDF directly from SoapUI but you can save response as pdf.


        Use dump property of REST method to save Pdf,Word or zip files. Call below code before executing REST method :


        testRunner.testCase.testSteps[thisTestcase].testRequest.dumpFile = <path to dump file.extension>


        Hope this helps.

  • rupert_anderson's avatar
    Valued Contributor



    This is an interesting question...


    Whilst SoapUI can send PDF files as attachments as part of SOAP attachments, as far as I am aware I don't think any of the versions can actually display PDF responses..


    Presumably you would actually also like to query document properties / do assertions on the PDF response? 


    (unless someone else can jump in with a solution)


    My thoughts on doing this would be:


    1. Use a Groovy TestStep to get the response data and build a PDF document object using some kind of PDF library e.g. IText. Presumably it would then be possible to dump it to file / test it with Assertions.
    2. Write a SoapUI plugin to do something similar. This would probably be more complicated, but possibly allow you (with sufficient effort) to customize the way SoapUI deals with the response.

    Of course this isn't a direct answer to your problem, but if I can find the time I'd be happy to discuss / work on it together if you're interested? 




    • Premier2k's avatar
      Occasional Contributor

      Hi Rupert,


      Many thanks for your response. I figured that would be the case.

      I might have a look at the SOAPUI plugin route, a couple of the developers here are itching to get writing something like that so I may work jointly with them on this.


      Kind Regards,


      • rupert_anderson's avatar
        Valued Contributor

        Hi Paul,


        No problem, I reckon it's an interesting topic! 


        In terms of actually viewing a PDF e.g. when the response content type is application/pdf, then I thought creating a new response tab might be the nicest solution. Although I think this would probably be best done as a feature request i.e. change to the source code, and may not actually be doable as a plugin.. but this was just my take on what you wanted, there are many other ways to view the PDF with a bit of coding!


        Good luck with whatever you choose to do and let me know if you need any help / suggestions, might experiment with the script route myself.... Probably others will want what you develop, will lookout for your plugin in the plugin library! :-)






  • Rakinson23's avatar
    Occasional Contributor

    I found this topic few days ago because I had similar problem. 
    Now I'm happy to have solution for this kind of case, but with some req. like:
    - you also recived your response as a JSON, and it is encoded in Base64 then you can use this kind of script in assertion for your request:


    import org.apache.commons.codec.binary.Base64; 
    import groovy.json.JsonSlurper
    //grab the response
    def content = messageExchange.response.responseContent
    def jsonSlurper = new JsonSlurper().parseText(content)
    assert !(jsonSlurper.isEmpty())
    document_content = jsonSlurper.fileContent
    def fileName = messageExchange.modelItem.testStep.testCase.getPropertyValue("DOC") + '_.pdf'
    new File( "F:\\Testing\\Testing1\\$fileName").bytes = document_content.decodeBase64() fileName


    as a result you should recive ready pdf file.