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
Sourav HazraSourav Hazra 

Documents are getting downloaded instead of displaying

Hi, 

We have a requirement of displaying document fetched through a web service. Please refer below the controller and page section to fetch the document and display in a new page 

We are able to fetch the document but facing issue while displaying the document in a new page. The document is getting downloaded whenever redirects to new page on a onclick function instead of opening the document in browser. Can you please suggest? 

Controller section
=================

public class ViewPdf {
    
    public String pdf{get;set;}
    public String mimetype{get;set;}
    
    
    public void fetchDoc(){
        XXXNoDm_v1.XXXDocumentServicePort test = new XXXNoDm_v1.XXXDocumentServicePort();
   
        pdf = test.getDocument('XXXXX','2000000','XXXXXX');
       
    }
    
    
    
    
    
}




Page Section
===================

<apex:page controller="ViewPdf" sidebar="false" showHeader="false" action="{!fetchDoc}">
    <!-- {!pdf} -->
    
    <iframe src="data:'application/pdf';base64,{!pdf}" height="110%" width="100%"></iframe>
    
  
    
</apex:page>
                      
Ashish_Sharma_DEVSFDCAshish_Sharma_DEVSFDC
Hi Saurav,

There is no in built function for this.

Please refer this link. http://pdfobject.com/markup/index.php.

Let us know if it helps.