Forum


Replies: 2   Views: 3344
Styling text when using addhtml()
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 patrick.white  · 29-02-2012 - 15:35

I'm trying to incorporate global styling across the entire docx file. I'm using <style> tags that style the content. However, I noticed something strange:

[b]This code works fine:[/b]
[code]
$docx = new CreateDocx();
$html= '<style>p {font-family:arial;font-size:33px;}</style>';
$html.= '<p>Some sample text. <strong><span>Some bold text.</span></strong></p>';
$docx->addHTML($html);
$docx->createDocxAndDownload('example_html');
[/code]




[b]This code fails![/b]
[code]
$docx = new CreateDocx();
$html= '<style>p {font-family:arial;font-size:33px;}</style>';
$docx->addHTML($html);
$html= '<p>Some sample text. <strong><span>Some bold text.</span></strong></p>';
$docx->addHTML($html);
$docx->createDocxAndDownload('example_html');
[/code]

In the second example, the style gets ignored. Why would adding the style coding separately fail?

Thanks,
-Patrick

Posted by admin  · 11-04-2013 - 12:13

Hello,

Because Word thinks they are different HTML content. Each addHTML method creates a new altchunk tag in document.
You must not think Word as HTML pages.

Regards. Jorge.