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
BrianWKBrianWK 

Apex Image with Static Resource on MS Word

Hey everyone. I have a page that we were rendering as a pdf. It was decided by the powers above that we wanted this as a Word document instead. I was hoping that I could easily make the switch by changing renderas="pdf" into contentType= "application/msword"  For grins, I also used .vnd.ms-excel and got the same red x.

 

For the most part this has worked. But I have one issue with an apex image on my page. It's calling a static resource (gif) which renders fine with a PDF or html - but shows up as a nice red X on the MS word. Anyone know how I can fix this? Is there a trick to using static resources for pages rendering as MS word  / excel that's different from PDF or HTML?

 

Page Code:

<apex:page standardcontroller="Opportunity" showheader="false" contentType="application/msword"> <!-- bunch of other stuff --> <apex:image url="{!$Resource.p1source_lrg_logo}" / > <!-- More bunches fo other stuff --> </page>

 

I don't change the apex image code at all between the renderas PDF, HTMl or setting the contenttype

Best Answer chosen by Admin (Salesforce Developers) 
cpebre3cpebre3

it seems to work for me if I use the complete URL. For instance, I can see my image document in the generated Word when I use this code:

 

<img src="https://ap1.salesforce.com/servlet/servlet.ImageServer?id=01590000000DB9H&oid=00D9000000

If I omit the https://ap1.salesforce.com part, it does not show the picture.

 

It is because the Word document is using the image as an external resource, not an embedded object....

 

It may also work for static resource...

 

Chris

All Answers

HarmpieHarmpie

I think, for word to be able to open an image, static resources are not possible (someone correct me if I am wrong). Placing the image in the documents folder as an externally available image would probably work though.

 

To check this, maybe have a look at the HTML code of your page (render it normally) and see what the img code is when using a static resource. My guess would be that this src attribute, when pasted in the browder will not work either.

hokusaihokusai
I have this same problem.  When will we have renderas="msword" and "msexcel" and other?
cpebre3cpebre3

it seems to work for me if I use the complete URL. For instance, I can see my image document in the generated Word when I use this code:

 

<img src="https://ap1.salesforce.com/servlet/servlet.ImageServer?id=01590000000DB9H&oid=00D9000000

If I omit the https://ap1.salesforce.com part, it does not show the picture.

 

It is because the Word document is using the image as an external resource, not an embedded object....

 

It may also work for static resource...

 

Chris

This was selected as the best answer
hokusaihokusai
I understand that
servlet/servlet.ImageServer?id=
works.  I do not understand why a static resource does not work in the code above.