Forum


Replies: 4   Views: 4491
Embedhtml(): how to style bold text when strictwordstyles = true
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 shroom  · 16-12-2015 - 22:50

We are building Word docx's by pulling text from a database.  That text has HTML in it.  A sample might be:

"The quick <strong>brown fox</strong> jumped over the lazy <strong>sleeping dog</strong>."

embedHTML() works fine, and displays the text as expected.

But what I want to do is make the bolded text a little smaller.  In HTML, this is easy: I just style <strong> tags with "font-size:90%".  But since I am using embedHTML with strictWordStyles = true, it discards all inline styles.  I understand this, and have tried several ways to get phpdocx to style bolded text like I need.

I have a custom style in the doxc I am using as a template that works fine.  I can select the words I want to apply the style to, apply the style,and they are bolded and made a little smaller.  With embedHTML, I have tried assigning my custom style to "<strong>" tags in the wordstyles() array, it does not work.  I have tried changing <strong>sleeping dog</strong> to <span class="myboldclass">sleeping dog</span> and assigning myboldclass to the custom style in the wordstyles() array, it does not work.

How can I get phpdocx to apply a custom style to <strong> tags?  Note that I have no problem applying custom styles to <p>, <h2>, etc tags, but I cannot figure out how to apply a custom style to <strong> tags.  Also note that if I class a <p> with "myboldclass", it works, the entire paragraph is bolded and the font made a little smaller.  But I do not want to class an entire paragraph, I want the class to apply to words within a paragraph.  According to the documentation, applying a custom style to a classed <span> should work, but it does not.

I hope that makes sense.

Thanks