Replies: 2   Views: 3430
Html in header and footer
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 bgcc  · 24-07-2013 - 06:56

The following code describes the way to use a HTML content string as header and / or footer in a DOCX. In this case no DOCX with template variables as template is used.


require_once '/vendor/phpdocx/classes/';

$docx = new CreateDocx();


/* HEADER */

$header_wordml = $docx->embedHTML('<table><tr><td>test</td><td align="right">test</td></tr></table>', array(

    'rawWordML' => true,


$header_wordml_fragment = $docx->createWordMLFragment(array($header_wordml));

$docx->addHeader(array('default' => $header_wordml_fragment));


$docx->embedHTML('<h1>Content</h1><p>Lorem ipsum dolor sit amet</p>', array(

    'downloadImages'    => true,

    'parseDivsAsPs'     => false,

    'parseFloats'       => true,


/* Footer */

$footer_wordml = $docx->embedHTML('<p align="center">Some text</p>', array(

    'rawWordML' => true,


$footer_wordml_fragment = $docx->createWordMLFragment(array($footer_wordml));

$docx->addFooter(array('default' => $footer_wordml_fragment));



If somebody find an easier way, please link it here.


Posted by admin-phpdocx  · 26-07-2013 - 11:40

I do not believe there is any other way to do it with the curent 3.3 version.