Replies: 1   Views: 2941
Create a block of text containing a header+text+table that doesn't split over pages?
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 jamie3000  · 03-11-2016 - 16:09

Hi Guys,

I'm trying to create a block of elements that looks something like below.


Text Description

Row3 etc

The problem I am facing is because the table has a dynamic amount of rows it will somtimes run onto other pages and I'd like it to stay with the heading and description by not running on to other pages. 

I am correct in assuming the best way to do this is to build up a word fragment containing these elements (heading, text and table) then use addText with keepLines to keep it all on the same page in one paragraph?

I tried this and I seem to get blank output. Below is how I'm using it.

$wf = new WordFragment($docx, 'document');
$wf->addText($BenefitData['TitleOfTable'], array('font' => 'Calibri Light', 'fontSize' => 16, 'color' => '2E74B5', 'bold' => false));
$wf->addTable($valuesTable, $paramsTable, array('cantSplitRows'=>true));

$wf_new = new WordFragment($docx, 'document');
$wf_new->addText($wf, array('keepLines' => true));
$docx->replaceVariableByWordFragment(array('BenefitTables' => $wf_new), array('type' => 'block'));

Can you see anything wrong with the above or can you think of a different/better way of doing what I'm trying to achieve?