News

Add page breaks in a docx document with PHPDocX

  • May 04, 2011

This information is outdated, please, refer to the addBreak documentation for up to date info.
Need to jump to another page? use a page break!
Wtih his code you will learn how to insert a page break into your Word document.


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

$docx = new CreateDocx();

// here we define some text
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' .
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut ' .
'enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut' .
'aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit ' .
'in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui ' .
'officia deserunt mollit anim id est laborum.';

// Adding the text
$docx->addText($text);

// Adding a pagebreak
$docx->addBreak('line');

// Adding more text and playing with pagebreaks
$docx->addText($text);

$docx->addBreak('line');

$docx->addBreak('line');

$docx->addText($text);

$docx->addBreak('page');

$docx->addText($text);

$docx->createDocx('example_pagebreak');