Forum


Replies: 1   Views: 3102
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.

Heading

Text Description

Table
Row1
Row2
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->addText($BenefitData['TitleDescription']);
$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?                 

Posted by admin  · 04-11-2016 - 07:55

Hello,

We don't recommend adding a WordFragment into other WordFragment. Please use a single WordFragment to add the content and try using keepLines and keepNext options to keep contents in the same page.

You can enable the same keepNext option in the rows of the table:

http://word.mvps.org/faqs/tblsfldsfms/keeptableon1page.htm

Regards.