Forum


Replies: 1   Views: 1407
Replacevariablebyhtml - keep font size and font face
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 royh  · 08-06-2021 - 20:25

I have a WYSIWYG editor where a user can capture HTML. When I use replaceVariableByHTML I want to import the HTML but keep the font size and font face the same as the template variable but allow the other elements of the HTML. How can I do this?

Here is the HTML it generates:

<ul>
<li>This</li>
<li>Is
<ul>
<li>A</li>
</ul>
</li>
<li>Test</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table style="border-collapse: collapse; width: 100%;" border="1">
<tbody>
<tr>
<td style="width: 50%;"><strong>Header</strong></td>
<td style="width: 50%;"><strong>Header</strong></td>
</tr>
<tr>
<td style="width: 50%;">Contents</td>
<td style="width: 50%;">Contents</td>
</tr>
</tbody>
</table>

Posted by admin  · 09-06-2021 - 06:45

Hello,

HTML to DOCX methods set a default font size and font family to handle all CSS styles and properties. Until the launch of phpdocx 10, when you replaced a placeholder using replaceVariableByHTML, the new contents applied font size and font family styles from the HTML/CSS (default styles when not set) overwriting the placeholder styles; so to apply the exact placeholder styles they needed to be added manually to the HTML/CSS or caught dynamically using getWordStyles.

Since the release of phpdocx 10, Premium licenses include the stylesReplacementType option in replaceVariableByHTML. This option allows mixing and replacing HTML/CSS and placeholder styles when doing replacements. We recommend you to read the information available about this option on https://www.phpdocx.com/api-documentation/templates/replace-variable-html-Word-document, and also checks the included samples in the package, that illustrates how to use this option.

Regards.