0

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.

  • 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 '16 at 8:16
  • Hi Kurunve, I tried with <img> tag but not get. – Vijay Kumar Feb 29 '16 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 '16 at 8:45
2

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

|improve this answer|||||
  • yes, it's worked for me. – Vijay Kumar Mar 2 '16 at 7:09
0

Use

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

instead of

servlet/servlet.filedownload?file=recordid

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 .

|improve this answer|||||
  • Hi Kalpesh, this is also correct. thanks for your explanation. – Vijay Kumar Mar 2 '16 at 7:10
0

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" /> 

Thanks

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.