Forum


Replies: 14   Views: 4203
Table of contents before variables.
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 jordyboytjuh  · 22-01-2015 - 08:15

If I use $docx->addTableContents(array('autoUpdate' => true)); it puts my table of contents below the declared variables in the template. Is there an option to put my table of content before variables? So on a certain page or in a other variable? I wan't to use the variables in the template, but need an table of content as well. Regards, Jordy

Posted by admin  · 22-01-2015 - 13:07

Hello, Please try adding a page break with this method: http://www.phpdocx.com/api-documentation/word-content/insert-line-column-page-break-Word-document-with-PHP and adding a new section: http://www.phpdocx.com/api-documentation/layout-and-general/add-section-Word-document-with-PHP Regards.

Posted by jordyboytjuh  · 30-01-2015 - 09:37

Hello admin, I don't really understand where I put my page break and section. I've two variables on the first page. And twho on the third page. Between them I want a table of contents, which is updated automatically. My code right now: $variables = array( 'TITLE' => 'Document', 'SUBTITLE' => 'Description', ); $docx->replaceVariableByText($variables); $docx->addBreak(array('type' => 'page')); $docx->addSection('nextPage', 'A4'); //Add table of contents to the document $docx->addTableContents(array('autoUpdate' => true)); $docx->addBreak(array('type' => 'page')); $docx->addSection('nextPage', 'A4'); $variables = array( 'PART1' => 'title', 'PART2' => 'description' ); //etc. My template is just as how I want it, on the first page there are 2 variables. Then 1 page blank and then 1 page with 2 variables again. The table of contents has to be on page 2. Can you help me? Thanks a lot! Regards

Posted by admin  · 30-01-2015 - 11:21

Hello, What version and license of phpdocx are you using? Regards.

Posted by jordyboytjuh  · 30-01-2015 - 11:25

I'm using the trial right now. It's version 4.1. Is it possible to add the table of content before variables in the template?

Posted by jordyboytjuh  · 01-02-2015 - 18:54

Is it possible in the trial? I don't understand your page break and section. Can you give me an example? Thanks in advance! Regards

Posted by admin  · 02-02-2015 - 11:00

Hello, If you're createing a new document the code is simple; for example: //path to the CreateDocx class within your PHPDocX installation require_once '../../classes/CreateDocx.inc'; $docx = new CreateDocx(); $docx->addText('Cover'); $docx->addBreak(array('type' => 'page')); $docx->addText('Another page'); $docx->addBreak(array('type' => 'page')); $docx->addTableContents(array('autoUpdate' => true), $legend, '../../examples/files/crazyTOC.docx'); //we add now some headings so tehy show up in the TOC $docx->addText('Chapter 1', array('pStyle' => 'Heading1PHPDOCX')); $docx->addText('Section', array('pStyle' => 'Heading2PHPDOCX')); $docx->addText('Another TOC entry', array('pStyle' => 'Heading3PHPDOCX')); $docx->createDocx('example_addTableContents'); If you're using templates you need to add the TOC with Word in the page you need it. You can't replace a placeholder by a TOC. Regards.

Posted by jordyboytjuh  · 02-02-2015 - 12:28

Allright, with a new document everything works fine. But is it possible to autoupdate an TOC that is allready placed in my template? So that the user get's an notification to update it? Or is that only possible with a new document only?

Posted by admin  · 02-02-2015 - 12:46

Hello, You'd need to add a macro that update it. Regards.

Posted by jordyboytjuh  · 02-02-2015 - 13:21

That's disappointing. So I can't work with a (filled) template and TOC together, with auto-update but without macro's (because of the notification in the beginning in Word). The only way is to put all the data in the php, with an addTOC in it to get the auto-update? Maybe it's an option to put a TOC where you declared it? So you set a place where you want the TOC, which auto-update works the same as the addTOC right now? We want a filled template but have a TOC as well (it's no problem if we put it in the template, or make it in PHP), but we want it on the second or third page, without macro's and update it automatically. Can you give the developers an request for this? I think more people are interested in it.

Posted by admin  · 02-02-2015 - 15:00

Hello, The Corporate and Enterprise licenses can do that by doing two or more merges. But the trial package doesn't include the merging class. Regards.

Posted by jordyboytjuh  · 02-02-2015 - 15:07

Thanks for the information! We've bought the Corporate license so I will look into the merging. Regards.

Posted by jordyboytjuh  · 03-02-2015 - 13:18

Thank you! It works with the merging, my TOC is refreshing when I'm opening the document. Last question, is there something like mergeDocxAndDownload? Like the createDocxAndDownload? So I can download my merged document? Thanks for all the information!

Posted by admin  · 03-02-2015 - 13:35

Hello, There's no method to merge and download. But it's very easy to do with a few headers, for example these are the headers used in the createDocxAndDownload method: header( 'Content-Type: application/vnd.openxmlformats-officedocument.' . 'wordprocessingml.document' ); header( 'Content-Disposition: attachment; filename="' . $fileNameDownload . '.' . $this->_extension . '"' ); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($fileName . '.' . $this->_extension)); readfile($fileName . '.' . $this->_extension); You just need to change the file path and add it to your code. Just remember you can't print anything before a PHP header. Regards.

Posted by Omnext  · 03-02-2015 - 13:36

Deleted by Omnext · 03-02-2015 - 13:38