html-to-docx
html-to-docx copied to clipboard
Image Issue with Tables
Hello Team
I hope you are doing well. I have used your NPM library html-to-docx for converting html templates to docx files. I am facing some issues with inserting images into them. I have tried multiple ways of inserting images inside html.
- Absolute URL - Links to an external image that is hosted on another website
- Relative URL - Links to an image that is hosted within the website. The above two methods didn't work for me. Then I tried with the base64 image data source and it worked for me. Now, when I am using base64 images within html template, I am facing some issues with the tables. The table border disappears and I am not getting the docx generated correctly. While if I do not insert any image to the html template, then the tables are working fine. I am using the official MS office to view the docs.
I have shared two sample docx files one with image and one without image.
The sample source code to insert an image -
<table style="width: 100%; border: none; border-spacing: 0; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0"> <tr style="border-collapse: collapse; border-spacing: 0;"> <td style="padding: 0px; margin: 0px; text-align: left; border-collapse: collapse; border-spacing: 0;" align="left"> <h1 style="color: #161950; font-size: 35px; font-weight: bold;">Tesla, Inc.</h1> <p style="color: #6565aa; font-size: 18px; font-family: 'Helvetica'; line-height: 17px; margin: 5px 0 20px; letter-spacing: 0px;">Company Snapshot</p> </td> <td style="padding: 0px; margin: 0px; text-align: right; border-collapse: collapse; border-spacing: 0;" align="right"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaEAAAB5CAMAAACnbG4GAAABMlBMVEX///8AAADS0tK9vb2EhIT7+/tMTEwMDAyMjIw+Pj6amppfX1+2trbCwsKqqqodHR1vb2/29vYKV6YSEhIYGBjo6OgkJCQITpoFQYrc3Nzy8vIJCQlHR0cJUZ4nJycHSZM1NTWQkJADOH5YWFhpaWkwMDB3d3fh4eHLy8tUVFSjo6OWlpYEPIMCNHmvr68AUaYAMIEAOYYAIW8AKnEATKfr8fhGd7QARpvP2+q/zuEAMH0AQ5QALH4APZIAKnShr8cAGWyGpM9ulMcucrkIZLOWstYAQqTh6/Wnwd9Xh8A1brHD0+V7msWzw9sZW6RlirxBbqsrXqBIcqxrg6xQa5wYQYEzVY6/x9aSpcN0i7FaeqqFmLiZp8IeT5IzToRO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BSmspxuvBreMoy+1hIe49HKhX43C2uVZi4ZRAMVdb7D3cyvfs/xw+86VZNctdg6CGsZ8yfQx4fAgPdjhrz1F5XVLRP8jDj/iRrjq1T5w+RSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUlJSUv/f+hfFwsHqHUmJ4wAAAABJRU5ErkJggg==" /> </tr> </table>
Can you please look into this issue and why there are table border issues when I am trying to insert an image in the html template.
Looking forward to hearing from you.
@gaganjot-kaur3197 Hope you are doing good as well. Currently images are only supported by base64 string, although a fix for external urls should be straight forward to implement. Happy to merge a PR, if you could raise one.
I am not really what table issue are you referring to because I tried opening it in WPS and it seems to have all the borders. Any chance you tried zooming in/out, I have seen some word-processor softwares kind of don't show borders properly on zoom levels even though it's actually there. Try zooming in/out to a different level and post it here?
Edit: Attaching the screenshots of the 2 docx in WPS
Hi @privateOmega ,
Thanks for the information. We have not made any changes in your module so far and implemented it in our application codebase only. If you already have a fix for this then can you please apply and release it.
Regarding table border issues, We are facing this issue only when we are adding images to the html templates. Otherwise, It is working fine for us.
Below are the screenshot for the docs,
The doc without image - 100% zoom level
The doc with image - 100% zoom level
The issue occurs on 110%, 130%, 150% , 160% zoom level etc.
@gaganjot-kaur3197 I also haven't worked on bringing support for external images to html-to-docx, so thats something that I could only take up whenever I become available. And like I said, are you facing issues at all zoom levels, I had already attached screenshots of the same documents, you had attached opened in WPS, chances are it must be a bug from MS Office, since it works smoothly on WPS, MS office products are known for buggy implementation of the standard even though people consider it as gold standards of word processing.Try opening the same document in different versions of MS office at different zoom levels, if its still an issue, we can look if something can be additionally.
Thanks @privateOmega for quick help. We will look into this. Please update once when you will work on external images support.
@privateOmega been watching this repo for a bit, isn't this addressed in #148 ?