Forum


Replies: 3   Views: 229
Unable to set default font style using replacevariablebyhtml() function.
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by turnercmt  · 13-05-2020 - 15:10

Hello, We have a premium license. We are using replaceVariableByHTML() function to replace the place holder with HTML. But when we get updated docx file after replacing the place holder the font size and font family not keep as document default stayling. Example: the deafult docx have a font family as "Times New Roman" and there is marker "$NAME$". Now we are replacing the "$NAME$" place holder by using replaceVariableByHTML() function to "John Doe". Now when we get new docx after replacing the "$NAME$"  as "John Doe" then the font family of the "John Doe" word is not keep as  "Times New Roman" it shows in "Calibri" font family and font size is 12.

So how we can keep default font styling of the docs file which get generated after replacing the place holder.

There is option to pass the font style for place holder value while calling replaceVariableByHTML() function. For using this we can set font style to the replaced text. But how we will get default style of the document.

Posted by admin  · 13-05-2020 - 15:56

Hello,

replaceVariableByHTML adds default styles to the imported contents, existing placeholder styles are replaced by the new ones. Using other replacement methods with inline replacements keep the styles from the placeholders, such as replaceVariableByText.

You need to apply the styles to be used to replaceVariableByHTML through CSS when transforming the HTML. You can get styles applied to contents using getWordStyles: https://www.phpdocx.com/api-documentation/docx-path/get-styles-word-contents-in-docx

You can also use custom styles when generating the DOCX from HTML: https://www.phpdocx.com/documentation/introduction/html-to-word-PHP (Using native Word formatting with HTML section).

If you send a DOCX sample to contact[at]phpdocx.com we'll generate a custom script to illustrate how to accomplish this task.

Regards.

Posted by turnercmt  · 14-05-2020 - 03:41

Thanks for your quick reply.
We will try as you suggested, if still problem is exist then we will email you the document.

Posted by turnercmt  · 14-05-2020 - 06:47

We have used suggested methods by you, but still we having issue so I have emailed you the all details on contact[at]phpdocx.com. Please check the same.