Hello,
Using addHeader and addFooter methods you can set first, default and even header and footer contents when creating a single section in the DOCX.
For example, to add to the existing section an empty header in the first page and a default header in the next pages:
$docx = new CreateDocx();
$headerFragment_first = new WordFragment($docx, 'firstHeader');
$headerFragment_first->addText('');
$html = '<p>HTML content</p>';
$headerFragment_default = new WordFragment($docx, 'defaultHeader');
$headerFragment_default->embedHTML($html);
$docx->addHeader(
array(
'first' => $headerFragment_first,
'default' => $headerFragment_default,
)
);
$docx->addText('Text first page');
$docx->addBreak(array('type' => 'page'));
$docx->addText('Text second page');
$docx->createDocx('output');
This works for documents with a single section. As you are doing now, to generate documents with multiple sections with their own headers and footers, you need to create a DOCX for each section and them merge them using mergeDocx.
Regards.