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
Vivek DeshmaneVivek Deshmane 

Issue on Apex callout with .NET web service that returns PDF file byte stream

Through apex call out i am getting following response from .Net Webservice  . How I will render/create as attachment  in salesforce as well formed PDF file based on below response.

JVBERi0xLjQNCiVET0MxIFJlc291cmNlR1VJRD01ODU4REFCNUQzQUY0RjY2QjU2Mzc5Mzg5NjI0NDYxMg0KJeLj5A0KMSAwIG9iag0KPDwgL1R5cGUgL1BhZ2UNCi9QYXJlbnQgMyAwIFINCi9SZXNvdXJjZXMgNCAw........

Please help . 
Best Answer chosen by Vivek Deshmane
Vivek DeshmaneVivek Deshmane

After doing lots of brainstroming, Finally, I have got sucess to render  pdf byte stream reponse  in salesforce using apex callout.

Step 1:- Apex callout
     Http http = new Http();
     HttpRequest req = new HttpRequest();
     req.setEndpoint(endPoint);
     req.setbody(body);
      req.setMethod('POST');
        HttpResponse resp = http.send(req);
        
//get Response body and parse it.
        Dom.Document doc = resp.getBodyDocument();
        
        //Retrieve the root element for this document.
        Dom.XMLNode transactionStatusDetails = doc.getRootElement();
        
                
        // Loop through the child elements.
        
        for(Dom.XMLNode child : transactionStatusDetails.getChildElements()) {
        System.debug('@@@@@'+child.getName());
          if(child.getName() =='PDFSummaryGetResponse'){
           Attachment attach = new Attachment();
       
                    attach.Body = EncodingUtil.Base64Decode(child.getText());

                    attach.Name = 'Invoice.pdf';

                    attach.ParentId = 'a3if0000000Csrd';

                    attach.ContentType = 'application/pdf';
            
                    insert attach;
        }
        }
2.Conclusion
To render PDF byte stream response from Dont net as PDF  in Salesforce first we have to insert it as attachment with help of EncodingUtil.Base64Decode() as Body content and display it on Page like .
pageReference pr= new pageReference('/servlet/servlet.FileDownload?file='+attach.id);
 

All Answers

Vivek DeshmaneVivek Deshmane

After doing lots of brainstroming, Finally, I have got sucess to render  pdf byte stream reponse  in salesforce using apex callout.

Step 1:- Apex callout
     Http http = new Http();
     HttpRequest req = new HttpRequest();
     req.setEndpoint(endPoint);
     req.setbody(body);
      req.setMethod('POST');
        HttpResponse resp = http.send(req);
        
//get Response body and parse it.
        Dom.Document doc = resp.getBodyDocument();
        
        //Retrieve the root element for this document.
        Dom.XMLNode transactionStatusDetails = doc.getRootElement();
        
                
        // Loop through the child elements.
        
        for(Dom.XMLNode child : transactionStatusDetails.getChildElements()) {
        System.debug('@@@@@'+child.getName());
          if(child.getName() =='PDFSummaryGetResponse'){
           Attachment attach = new Attachment();
       
                    attach.Body = EncodingUtil.Base64Decode(child.getText());

                    attach.Name = 'Invoice.pdf';

                    attach.ParentId = 'a3if0000000Csrd';

                    attach.ContentType = 'application/pdf';
            
                    insert attach;
        }
        }
2.Conclusion
To render PDF byte stream response from Dont net as PDF  in Salesforce first we have to insert it as attachment with help of EncodingUtil.Base64Decode() as Body content and display it on Page like .
pageReference pr= new pageReference('/servlet/servlet.FileDownload?file='+attach.id);
 
This was selected as the best answer
AmitabhleoAmitabhleo
Thanks for the Detailed explanination, I also was facing the same issue.

regards,
Amitabh
mbforcembforce
Well Explained....it will be helpful for many users!!!!