Search code examples
htmlcsspython-2.7doclibreoffice-writer

Why Python changes font settings when I replace a string in HTML template for a doc file


I'm having a HTML content as string (Template) and need to replace name and address fields inside HTML content before creating doc file from that HTML content. When there is no name present in db then I'm replacing as empty quotes. But this replace of empty string changes the font setting given in HTML content when we open the doc file.

How can rectify this?

I have tried like setting the font tag in the empty string but still no use.

Python Code:

html_content.replace('[[FULL NAME]]',full_name or '<font color="blue"><font face="arial"><font style="font-size: 8pt" size="1"></font></font></font>')

Piece of HTML template

    <td style="border: 1px solid #ffffff; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">

    <p style="margin-left: -0.02in; font-weight: normal"><font color="blue"><font face="arial"><font style="font-size: 8pt" size="1">[[FULL NAME]]</font></font></font>    
</p></td>

Solution

  • To rectify this send <br> tag inside the empty string. It will work!!!.

    Instead If we send &nbsp; inside empty string, inside the .doc file on the libre writer it will show Field Shadings while the document if opened in edit mode. That's the main issue, that's why I asked this question here.