0

I would like to know whether it is possible to add an embedded image in Word document when developed from Visualforce page so that when user opens the same document after downloading, the image is displayed even when the user is offline.

1
  • 2
    Point of clarity: Visualforce does not render Microsoft Word documents. It renders HTML that Microsoft Word, due to a behavioral quirk, is willing to open and render if you claim it is a Word document. Whether or not this is even possible is dependent on the details of Word's HTML renderer.
    – David Reed
    Commented Nov 28, 2019 at 5:04

1 Answer 1

1

I've not seen any functionality for rendering Visualforce pages as a .doc, but Salesforce provides some guidance here. You must use contentType="application/msword#filename.doc", applyHtmlTag="false", and applyBodyTag="false" in your initial <apex:page> tag.

From there, I believe you'd be able to give the image tag it's source as raw, base64 data rather than a URL. This would mean querying for the static resource in the Visualforce page's Apex controller, and possibly manipulating it there, before giving it to the Visualforce page like so:

<img src="data:image/png;base64, {!yourImageData}"/>
5
  • this is not working the image is not been displayed on word document . Can you provide some snippet to get help with the same. Commented Nov 26, 2019 at 6:40
  • I'm afraid not, I've never rendered a Visualforce page as a .doc let alone tried to embed an image inside. What've you tried so far? Commented Nov 26, 2019 at 9:18
  • I have tried extracting images from the following :1. Files 2. Static resouces 3.Document . But in all the above the image is not rendered on word document and the text is being rendered. Commented Nov 27, 2019 at 16:16
  • 2
    I should have specified: how're you currently trying to display the image in the Visualforce page? I assume you're using an img tag, and setting the source to a URL? I don't think that will work, as I imagine Word is not able/ permitted to reach out to unknown URLs to fetch images, so you have a better chance if you include the image's raw data instead. Commented Nov 28, 2019 at 8:44
  • Thanks @Dan Wareing . Point noted! Commented Jan 12, 2020 at 12:56

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