Forum


Replies: 5   Views: 2923
Generating toc using templates and embedhtml
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 admin  · 30-10-2017 - 15:00

Hello,

Maybe you didn't set the correct heading levels that must appear in the TOC? On this page you can find more information about TOCs:

https://www.phpdocx.com/documentation/cookbook/tables-of-contents

This is a simple script that generate a DOCX from scratch adding a TOC and two headings (note the displayLevels option):

<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->addText('Table of Contents', array('bold' => true, 'fontSize' => 14));
$legend = array(
    'text' => 'Click here to update the TOC', 
    'color' => 'B70000', 
    'bold' => true, 
    'fontSize' => 12
);
$docx->addTableContents(array('autoUpdate' => true, 'displayLevels' => '1-3'), $legend);

$html = '<h1>Heading 1</h1>';

$html .= '<p>Other text</p>';

$html .= '<h2>Heading 2</h2>';

$docx->embedHTML($html);

$docx->createDocx('output');

If you open the DOCX with MS Word or LibreOffice and then update the TOC, both heading appear in the TOC.

Regards.