Forum


Replies: 1   Views: 3710
Modify page layout within fragment
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 larrytech  · 11-03-2015 - 10:16

I have an interesting scenario where I need to change the page layout multiple times within a fragment. Our client creates pages through a web interface and can choose whether they are portrait or landscape. In the template for PHPDocX we have a $PAGES variable with is replaced via the replaceVariableWithWordFragment function. Each page will be written to the same fragment and it's orientated will be changed based on the orientation chosen for that page in the web interface. We call $fragment->addBreak(['type' => 'page']) between each page and potentially changing its orientation again (so multiple different orientations within the same fragment). The $PAGES variable is then replaced with the fragment. Is there a suitable way to go about this in PHPDOCX? If I try and call modifyPageLayout on the fragment I get the following errors: Fatal error: Call to a member function getElementsByTagName() on null in CreateDocx.inc on line 4498 PHP Warning: DOMDocument::loadXML(): Namespace prefix w on body is not defined in Entity, line: 1 in CreateDocx.inc on line 985 PHP Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 1 in CreateDocx.inc on line 985 PHP Notice: Trying to get property of non-object in CreateDocx.inc on line 5807 PHP Fatal error: Call to a member function getElementsByTagName() on null in CreateDocx.inc on line 4498

Posted by admin  · 11-03-2015 - 11:59

Hello, The current version of phpdocx doesn't allow to do that dinamically changes with templates. The addSection method allows to do that but only creating documents from scratch. Maybe you could do it using the MultiMerge class. This is working with documents and merge them to get the derised output. About your error, not all methods allow to be used with WordFragments. Anyway we'll consider adding it or a similar approach. Regards.