Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display images in Word generated from HTML?

I'm currently creating a Word document by generating HTML and changing the header information to display as a .doc file. It's a poor man's method, but it works just fine (until now).

I was just asked to include an image in the file. My best idea was to base64 embed the image. This works fine in a browser, however Word just gives me a box with an X in it.

Suggestions on how I can embed an image into this file and have it display in Microsoft Word?

like image 576
St. John Johnson Avatar asked Feb 24 '10 21:02

St. John Johnson


People also ask

How do you display images in Word?

Click the Microsoft Office Button, and then click Word Options. Click Advanced. Under Show document content, click to select the Show drawings and text boxes on screen check box. Click OK.

Does Word automatically embed images?

Images inserted from a file are embedded by default; you have to choose to link them.


1 Answers

That's a tough one, Word isn't able to handle data: base64 encoded images in HTML, at least that's the outcome in this question and this MSDN discussion.

You have three options:

  • Create a folder in the location of the document, store it alongside the document, and reference images relatively (<img src='imageFolder/image1.jpg'>)

  • Work with absolute URLs or file paths (even more sucky)

  • Look into the new Word > 2003 XML based file format(s), it is definitely possible there.

The only other option I can think of is actually creating a native Word file, e.g. using OpenOffice.

like image 183
Pekka Avatar answered Sep 17 '22 15:09

Pekka