How to display images in Word generated from HTML?

后端 未结 4 1670
自闭症患者
自闭症患者 2020-12-10 05:55

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

相关标签:
4条回答
  • 2020-12-10 06:15

    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.

    0 讨论(0)
  • 2020-12-10 06:27

    I just achieved this by printing the DOCX to PDF then using Acrobat to Save As to HTML. Images showed up small, but there.

    0 讨论(0)
  • 2020-12-10 06:32

    You can use this html-docx.js

    You just have to call htmlDocx.asBlob("YOUR HTML")

    Link to sample html to doc generation with image.

    0 讨论(0)
  • 2020-12-10 06:33

    I had the similar problem. I solved it by decoding the Base64 images to disk and creating a link to the images, deploying a servlet in my application to listen to the link pointed by images on disk. Here is the solution I implemented:

    How to convert HTML to well formed DOCX with styling attributes intact

    0 讨论(0)
提交回复
热议问题