Forum


Replies: 7   Views: 4577
Create toc when use a template
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 Sven May  · 11-02-2015 - 14:09

I would like ask that how I can make a TOC when I am using a template. ...because I have to use a word template I make a docx object with new CreateDocxFromTemplate(); I would like to add TOC on the 3rd page so I use varibale. To replace this variable I tried to use WordFragment class to change the variable for a real TOC...but it is not work :( part of my code: $docx = new CreateDocxFromTemplate($template); $wf = new WordFragment($docx); $wf->addText('Table of Contents', array('bold'=>true, 'fontSize'=>16, 'font'=>'Arial')); $wf->addTableContents(array('autoUpdate'=>true)); $wf->addText('Table of Contents', array('bold'=>true, 'fontSize'=>16, 'font'=>'Arial')); /* with WordFragment not work to add option like: array('autoUpdate'=>true) got this error msg: PHP Fatal error: Call to a member function getElementsByTagName() on a non-object in ...................../Symfony/vendor/phpdocx/src/Phpdocx/src/Classes/Phpdocx/Create/CreateDocx.inc on line 6104 */ $wf->addTableContents(); $wf->addText('Chapter 1', array('pStyle' => 'Heading1PHPDOCX')); $wf->addText('Section', array('pStyle' => 'Heading2PHPDOCX')); $wf->addText('Another TOC entry', array('pStyle' => 'Heading3PHPDOCX')); $docx->replaceVariableByWordFragment(array('TOC'=>$wf), array('type'=>'block')); Can I get any help what's wrong? The result is a non linked TOC without page number.