Saturday 30 November 2013

Showing image in the ms-word document from vf page of Salesforce.





Hi guys,


I am writing this because one of my friend get stuck in this requirement, I am also get surprised why the image is not showing in the MS-Document,

then finally I got its solution.

Here the code for the VF-Page,

   <apex:page sidebar="false"
            showHeader="false"
            contentType="application/msword#Test.doc"
            cache="true">

<head>
                        <meta http-equiv="Content-Type" 
                               content="text/html;charset=UTF-8" />
</head>

<img src="Document_URL" />
    </apex:page>

--> Document_Url is the url of the your image uploaded in the Document object of Salesforce.
--> cache = "true" for IE.

Hope  it helps...
Happy Coding...

Thanks,
Anurag Jain.

3 comments:

  1. Hi Anurag,

    Nice Post.
    I tried this code on my SFDC login. Everying fine but image not added in ms doc.
    please find below is my sfdc document url.
    SFDC URL: https://ap1.salesforce.com/01590000005WO0L
    suggest me the correct way.

    ReplyDelete
    Replies
    1. Hi Manohar,

      i cant see your url bz its ask for login credential as it is internal sf link,
      and i checked this code again it is working perfectly.

      i think there may be issue of document url
      please give correct url in image tag.

      Thanks
      Anurag Jain

      Delete
  2. Manohar,

    The problem may also be due to secure URL. The url should be : http://ap1.salesforce.com/01590000005WO0L than "https....." .
    I know by now the issue might be resolved, but this may occur to anyone else referring this page.

    Thanks,
    Shefali

    ReplyDelete