I am generating word document. In the document images are not displaying in header. Images are getting from documents. Below is my code..

My VF Page:

<apex:page standardController="CustomObject__c" extensions="GenerateWordController" contentType="application/vnd.msWord#HR_WordDocument.doc" cache="true" applyHtmlTag="false" showHeader="false" readOnly="true">
<apex:image value="{!ESLogo}" width="30" height="30"/>&nbsp;&nbsp;&nbsp;&nbsp;<apex:image value="{!ESLogo1}"/>

My Controller:

public class GenerateWordController
    public String ESLogo                       { get; set; }
    public String ESLogo1                      { get; set; }

    public GenerateWordController(ApexPages.StandardController controller) 
        tempString = '/servlet/servlet.FileDownload?file=';

        ESLogo = tempString;
        ESLogo1 = tempString;

        List<document> documentList = [SELECT id, 
                                        FROM   document 
                                        WHERE  NAME LIKE 'ESLogo%' 
                                        ORDER  BY NAME ];
        if(documentList.size() > 0)
          ESLogo = ESLogo + documentList[0].id;
          ESLogo1 = ESLogo1 + documentList[1].id;
          System.debug('documentList[0].id+++++++++' + documentList[0].id);
          System.debug('documentList[1].id+++++++++' + documentList[1].id);

I am getting the image id's in system.debug, but images are not displaying in word document.

  • 1
    I am pretty sure that image is stored as link, not as picture itself. Can you try to use insead of apex:image just img tag with src as binary data -- like here jsfiddle.net/hpP45
    – kurunve
    Feb 29, 2016 at 8:16
  • Hi Kurunve, I tried with <img> tag but not get. Feb 29, 2016 at 8:40
  • then, there is no way to do it in SF. You can try s-docs extension, it has 2 free templates, and that may be what you need, or al least suits your request
    – kurunve
    Feb 29, 2016 at 8:45

3 Answers 3


I had a very similar issue while exporting it to excel. Image not getting displayed in exported excel from VF page

Build your url like this https://mydomain.my.salesforce.com/servlet/servlet.ImageServer?id=015a00000030EqL&oid=00D30000000X7qS&lastMod=1392744621000

where id = documentid and oid is organization id and make sure you have the image as externally available in your document. Hope this helps

  • yes, it's worked for me. Mar 2, 2016 at 7:09


servlet/servlet.imageserver?id=record id&oid=orgid 

instead of


The servlet/servlet.imageserver?id= allows us only to view the image in browser window while the servlet/servlet.filedownload?file=,downloads the file from your browser to download location .

  • Hi Kalpesh, this is also correct. thanks for your explanation. Mar 2, 2016 at 7:10

This Can simply be achieved in 2 ways

1.Copying the link like shown in below article

Right click the image itself and copy its full URL. In Google Chrome, you would right click the image and click Copy image address. In Firefox, you would right click the image and click Copy image location. In Internet Explorer, you would right click the image and click Properties, and then copy the URL from the "Address (URL)" field in the following pop-up window. enter image description here You can now add this image into your template by clicking the Add Image button icon in the

2.The second way it putting the DOC id and ORG id in below format

<img id="theImage" src="https://swapnilsrivastav-dev-ed--c.na46.content.force.com/servlet/servlet.ImageServer?id=0150H00000GEhAm&oid=00Di0000000joS6&lastMod=1576580776000" /> 


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .