[SalesForce] images not displaying in word document

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, 
                                               NAME 
                                        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.

Best Answer

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

Related Topic