function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Display a pdf obtained in HTTP Response,



I am calling a servlet from my apex code, i am getting a pdf stream as response, the whole pdf is available in the response.getBody()... But i dont know how to display the pdf now.


Here is what i did


public void GetDocument()
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        HttpResponse res;
        res = http.send(req);
        pdfData = res.getBody();


My VF Page:


    function showDocument()
        var htmlstr = '<html></head></head><body>sdfsfsdfsdf<object width="400" height="500" type="application/pdf" data="'+docData.value+'"/></body></html>';
        window.frames[0].document.body.innerHTML = htmlstr;          

<apex:commandbutton action="{!GetDocument}" value="GetDocument" reRenderer="docpanel"/>


 <apex:outputpanel id="docpanel">

         <apex:inputHidden id="docData" value="{!pdfData}"/>

                   docData = document.getElementById("{!$Component.docData}");


        <iframe scrolling="true" id="theIframe" onLoad="showDocument()" type="application/pdf"/>
        <object width="400" height="500" type="application/pdf" data="{!pdfData}" id="pdf_content"/>
        <apex:outputtext value="{!pdfData}" id="outputtemp"/>


when my apex method getDocument gets over, the outputPanel docPanel will get re-rendered, thereby calling my javascript method showDocument() which is in onLoad of my iframe...


I am trying to put the document inside iframe or in the object.. but it just stays empty, the pdf document is not getting displayed......


But in the outputText "outputtemp" the whole pdf is printed as a string, starting as %pdf- ... .............. <EOF>, this confirms i am getting the document.


Please help me in displaying the pdf in iframe or in the object tag.... what am i doing wrong here? if there is any workaround also please let me know.






I'm not thinking hard about your question as I'm not sure this is the best way to do it.  But, this just caught my eye:


var htmlstr = '<html></head></head><body>sdfsfsdfsdf<object width="400" height="500" type="application/pdf" data="'+docData.value+'"/></body></html>';




var htmlstr = '<html><head></head><body>sdfsfsdfsdf<object width="400" height="500" type="application/pdf" data="'+docData.value+'"/></body></html>';


Best, Steve.




Sorry it was a typo, i changed it, but still the problem persists




Any new insights considering this topic?