+ Start a Discussion
Admin FactorAdmin Factor 

Rendering a PDF in a Visualforce page after getting Blob webservice response

Hey there,

I am trying to render a PDF in a Visualforce page and I tried every possibility I found. This is my webservice (from the controller ShowInfoFactura) which gives a SOAP envelope response after calling it:
webservice static Blob getPDFMethod() {
        String theResult, theFinalResult;
        Blob blobby;
        try {
            // Web Service Calls
            // (...)
            wsResponse = wsPort.getWSResponse(ApexPages.currentPage().getParameters().get('id')); // SOAP envelope
            theResult = String.valueOf(wsResponse); // String
	        List <String> splitTheResult = new List<String>(theResult.split('result'));
            String theResultString = splitTheResult.get(2);
            String theResultStringRight = theResultString.right(theResultString.length() - 1);
            theFinalResult = theResultStringRight.left(theResultStringRight.length() - 3);
            blobby = EncodingUtil.base64Decode(theFinalResult);
        }
        catch (System.Exception ex) {
            ApexPages.addMessages(ex);
  			return null;
        }
        return blobby;
    }
These are the results (USER_DEBUG):
  • theResult (SOAP envelope): 17:00:00:517 USER_DEBUG [5]|DEBUG|The custom response is: wsResponse:[apex_schema_type_info=(http://jws.client.factory/, false, false), field_order_type_info=(message, result, status), message=null, message_type_info=(message, http://jws.client.factory/, null, 0, 1, false), result=JVBERi0xLjQKJeLjz9MKNSAwIG9iago8AxDL2rgKdlVtWsyxMqy3f1atrQvgtneJKOADeQU/Ds5njLlfLohtg3ee73unERvYmoKMTkgMCBvYmoKPDwvY2EgMT4+Pi9QYWdlcyAxNSAwIFI+XS9JbmZvIDM4IDAgUi9TaXplIDM5Pj4Kc3RhcnR4cmVmCjIzNjI5OAolJUVPRgo=, result_type_info=(result, http://jws.client.factory/, null, 0, 1, false), status=1, status_type_info=(status, http://jws.client.factory/, null, 1, 1, false)]
  • theFinalResult (Encoded PDF String): JVBERi0xLjQKJeLjz9MKNSAwIG9iago8AxDL2rgKdlVtWsyxMqy3f1atrQvgtneJKOADeQU/Ds5njLlfLohtg3ee73unERvYmoKMTkgMCBvYmoKPDwvY2EgMT4+Pi9QYWdlcyAxNSAwIFI+XS9JbmZvIDM4IDAgUi9TaXplIDM5Pj4Kc3RhcnR4cmVmCjIzNjI5OAolJUVPRgo
My visualforce page:
<apex:page controller="ShowInfoFacturas" renderAs="pdf" applyBodyTag="false">
    <head>
        <style> 
            html, body, p { font-family: 'Arial Unicode MS'; }
        </style>
    </head>
    <body>
        <center>
        <h1>Factura</h1>
        <apex:panelGrid columns="1" width="100%">
            <apex:outputText value="{!PDFMethod}" escape="false"/>
            <apex:outputText value="{!NOW()}"></apex:outputText>
        </apex:panelGrid>
        </center>
    </body>
</apex:page>

It does not show me the PDF, does anybody know how to do it properly? 

Thank you.
Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi Konozca,

 can you use try the  blob.toPDF before displaying pdf content on vf page .

For more reference follow below link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_blob.htm
Admin FactorAdmin Factor
Ankit Gupta@ Developer,

You mean something like this (replacing the code posted):
List <String> splitTheResult = new List<String>(theResult.split('result'));
String theResultString = splitTheResult.get(2);
String theResultStringRight = theResultString.right(theResultString.length() - 1);
theResult = theResultStringRight.left(theResultStringRight.length() - 3);
blobby = Blob.toPdf(theResult);
It is not working at all. Can you be more specific?