Forum


Replies: 1   Views: 32
Replacevariablebyhtml keeping word styles

Posted by andrewk1983  · 17-04-2025 - 06:21

Hi all,

Using latest Word create blank document and set its font size to 9 (usual default is 11 or something). Add some static text and then a bookmark, which will be replaced with the following HTML content:

<p>Some text<br /><br />Some more text</p><p>Some text</p><p>&nbsp;</p><p>Some more text</p>
Save the file run script to replace abovementioned bookmark. The font size for the replaced bookmark changes to 12. Also <p> tags aren't being treated with new lines (although a paragraph should behave like a paragraph, right?).
 
What am I doing wrong here? Any help is appreciated!
 
 

Posted by admin  · 17-04-2025 - 07:06

Hello,

We have done a quick test with your HTML and replaceVariableByHTML, and it's working correctly. Maybe you are not using the required license or phpdocx version.

Please note that you need to use a Premium license with the stylesReplacementType option to keep or mix placeholder and HTML styles when replacing a placeholder with HTML. Please check the documentation available on https://www.phpdocx.com/documentation/cookbook/keep-font-sizes-templates-importing-html

Regards.