Forum


Replies: 3   Views: 3775
Predefined word style lost in embedhtml() if html contains ul tag
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 Sven May  · 12-05-2015 - 08:23

Hi! As I experienced if I insert an HTML text into word document and the HTML text contains ul TAG after the close ul TAG the text lost the set predefined word style. Example: $html = 'Lorem ipsum....
Lorem ipsum....'; $docx = new CreateDocxFromTemplate($template); // $template doc include the predefined word stlye... $docx->embedHTML('[p]'.$html .'[/p]', array('strictWordStyles'=>true, 'wordStyles'=>array('[p]'=>'description'))); $docx->createDocx('generated_doc'); Of course change all [] brackets to the right HTML TAG brackets. So after the close ul TAG the second "Lorem ipsum..." text wont formatted with description style... Thank you!

Posted by admin  · 12-05-2015 - 12:18

Hello, All texts must be surrounded by a tag. Please add the needed tags for both strings, for example a span, and try again. Regards.

Posted by Sven May  · 12-05-2015 - 12:33

I found out that need wrap all text for example in paragraph. I just realised that my example htlm text has fail...missing the list part: $html = 'Lorem ipsum.... [ul][li]list1[/li][li]list2[/li][/ul]Lorem ipsum....'; My html content come from database therefore I can not affect that wrap it paragraph or for example span TAG text by text. So it means that in this case I have to write an own parser? So as you see my html content surround a [p] TAG: $docx->embedHTML('[p]'.$html .'[/p]', array('strictWordStyles'=>true, 'wordStyles'=>array('[p]'=>'description'))); ...but! The ul TAG break the paragraph contet and after the close ul TAG lost the format... I can not make that after the close ui TAG reopen the [p] TAG becasue the HTML text edited by the customer. I can not modified it!

Posted by admin  · 12-05-2015 - 14:15

Hello, No, you don't need to create your own parser. You can use Tidy (http://php.net/manual/es/book.tidy.php) to fix HTML content and add new tags. Or maybe your editor can add that thags; tools such as ckeditor adds all tags. Regards.