Skip to main content

HTML to DOCX

There are use cases when you want to insert HTML content into a document, for example in case of a rich text editor, where some of the data is filled in by the creator of the document and this is transplanted into the docx, while the rest of the information (customer name, address etc.) is filled in by the system. LabraDocs supports this in one go.

How to use it

In order to use this feature, you need to create a docx template with a mergefield, which will be replaced with the HTML content. The mergefield can be named as you like, but we recommend using a naming convention which makes it easy to identify the fields in the docx document. In the data section of the JSON file, you need to supply the HTML content in the following format:

{
"CUSTOMERNAME": "Jens Jensen",
"CUSTOMERADDRESS": "...",
"HTMLCONTENT": "<p>Some HTML content</p>"
}
note

Mergefields within HTML content are not supported.

Images in HTML

available from v1.3.0

Base64 encoded image fields are supported inside HTML content and they will be inserted into when replacing the HTML mergefield.

    <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5gkPDBsXekWXIQAAA2VJREFUOMttlE+IVlUYh5/33HPu/WYGGUehlTGbVqVlm4gWkgRBhEGuctMi+mMNSSVFmwqiEkGlCGpR2MoEoVIiB6KNi6JaaESrduFC6M+EYJ8zc855fy3u/eYbywtndeG5v/f3vPcYmx6dugscI9iiYD+wD9lOZNukRvLmT9X4k2o6q5rONWntSskdo2e/3mDYFLYbYBZ0AOyQ4A6gQQF5QN4gj6gmVFNWSRe9dMc9d+cs+Prc4TNToD7dDWIB9CZmT0l0/Vd6GGpQjahGvCZUW7y0KHfXvHQnfH3mKFbH8699jA3JZkBHMVuSCD3MkAJsJBtgpdUAMy8jPHfZS/dWvb7lnZBWSwCB6QBmT98cNk3Xjxt/xOOTXrovPXfF8ygpdy9hekg1ETEWwZ6fjmmgMIzbVHlzXgqX5Y2ppL0q7Vpdn1v20n7mefShl+6ASjuvml6oJX0XgEcRO6ewPl0vockovBdnry55nnnRy+iCl26PavpCNW73PHNSpV310uKlvVceH4hg+wRxIl3/sYpCXf1j8XbUHFdJd3rp8Nzd43l0TCWuDNZRTbPy5uEoseu/RvEIQ28oSJ62yps9XttZz92qarqomnbJ42299Yhqg7y5OwDb+jFt0hvyBh92zksyzy3KXX9q+hZ4xPPotGrqN8Aj8gbU3BLBlmCATWSomRiuePhVHh2Ph+TRUbiQr20PyPZO7NPDkAJRNZ6Vh7jxF5RhcXOHl06qzV/lnwWhZtlzG1TbRWRH5PE+eZyuVh/m94jsGNj9yBzZIMYm67OGwuNgGXEKbE6yeXnY0ncWN8OQ7FKUwkV585g8TlPWFu9/r1XVZqSSgtTcqppm+97S/2DIxsBXQR4/p8ZfVCMqCS8JL8PIucPLSF7b/t2NRsE3YAi+R3wT6nj+N6/pfdW02nfYotyi0g2nHXodYBtGJxINwVXEu2asBMxB4bRK+5GX1r10TM9wq3gPY7NRn8AsI04AyxKE0dIyZbz1utf4hpfuAy/dWj9quyndNNkNvWHXEEfAjoGVHScP9rfL3OEzlPHC36rpFZX2OdX2Z5W2ek2mmuwmRrOwHySeAHsbGO84+cyNNzbAyqsvM1q4bOOVxUWVbr/X9kE8vF7XZxOy83izKoVLKJyVOGcNV1RgxycHNxj/AigPt2r5yetCAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDI0LTAxLTE4VDE2OjAwOjM2KzAxOjAwG2NKsQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMi0wOS0xNVQxMDoyNzoyMyswMjowMI5WCuMAAAAASUVORK5CYII=" alt="image" title="image" />

If you would like to study further examples, take a look at the examples folder.

For learning how to replace images in docx templates, please continue to the next chapter.