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
vicky rathivicky rathi 

show Doc content on vf page

I am new in Salesforce. I want to show the Doc content on my vf page . I am able to show the PDF and Txt Content on the same page 
but when try to show the doc content its download or its show the cript formate. 

page code

 <!--    <apex:iframe frameborder="true" src="https://c.cs24.content.force.com/servlet/servlet.FileDownload?file={!pdf}" scrolling="true" id="theIframe" width="470px" height="250px"></apex:iframe> -->
         
       <apex:iframe frameborder="true" src="data:{!att.ContentType};base64,{!pdf}" scrolling="true" id="theIframe" width="470px" height="250px"></apex:iframe>  

controller code 
 public Document att {
        get {
            if (att == null) {
                att = [SELECT Id,Body, ContentType, Name FROM Document WHERE Name =: 'vcc credential data'];
            }
            return att;
        }
       private set;
    }
    public String pdf {
        get {
            
            List<Attachment> attch = [Select Id,Body, contentType, name from Attachment where  parentId =: AccountIdStr and Name='vcc credential data2.docx'];
                   // Blob  file = attch[0].body;
              system.debug('.......attch.........'+attch);
            if(attch!=Null && attch.Size()>0)
            return    EncodingUtil.Base64Encode(attch[0].body); 
                     //  return attch[0].Id;
            else  return  EncodingUtil.Base64Encode(att.body);
                          //  return att.Id; 
        }
Any One guide me how to show the doc content on vf page
               
 
Naveen DhanarajNaveen Dhanaraj
  1. Upoload the PDF file in to static Resources.
  2. open the file from Static Resources and take the URL.
  3. Pass the URL in to "src="https://c.ap2.visual.force.com/resource/1474956238000/pdf"
I have tried this, it works fine for me.

Code I have used:
<apex:page standardController="Account">
  <iframe src="https://c.ap2.visual.force.com/resource/1474956238000/pdf" ></iframe>
</apex:page>

 
vicky rathivicky rathi

@Naveen Dhanaraj

 I want to show the word content only from attachment account related not a pdf file .

PDF and TXT file showing in the vf but my requirement is show doc content

Thanks

Naveen DhanarajNaveen Dhanaraj
Sorry Vikas..I am confused
vicky rathivicky rathi
@Naveen Dhanaraj

I am upload a doc file in attachment  and want to show in my vf page using the <iframe > tag.
doc file not showing on the vf page its downloaded or show unreadable format.
I am upload the txt file and pdf file thats file showing on page .
My question is how to show the doc file on vf page (its a client requirement )