News

Headers and Footers in PHPdocx

  • May 03, 2011

Oftentimes it is necessary to put vital information about your document either at the top of the page, at the bottom of the page, or a combination of both. While you can easily enter things such as document title, page numbers, creation date, author, etc. at the top or bottom of your document body, if you place them in a header or footer outside of the document body, you can rest assured that this information will always retain the correct placement, no matter how much you edit the content of your document.
With PHPdocx is easy add headers and footers using the proper code: this is an example with text properties:


require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$paramsHeader = array(
'name' => '../files/img/image.png',
'jc' => 'right',
'textWrap' => 5,
'font' => 'Arial'
);

$docx->addHeader('Header Arial', $paramsHeader);

$paramsHeader = array(
'font' => 'Times New Roman'
);

$docx->addHeader('Header Times New Roman', $paramsHeader);

$paramsFooter = array(
'pager' => 'true',
'pagerAlignment' => 'center',
'font' => 'Arial'
);

$docx->addFooter('Footer Arial', $paramsFooter);

$paramsFooter = array(
'font' => 'Times New Roman'
);

$docx->addFooter('Footer Times New Roman', $paramsFooter);
$docx->createDocx('example_header_and_footer');