Forum


Replies: 3   Views: 3815
Trying to use custom paragraph styles as headings included in table of contents
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 account33640  · 18-01-2016 - 19:50

I don't know if I am misunderstanding the array $legend component for addTableContents or misusing the createParagraphStyle methods (or whatever else I have wrong).  The result is that custom paragraph styles with an orange font intended to be used as headings (and therefore appear in the table of contents) get created at 1/2 the intended font size, and only one of my two headings gets included into the table of contents.  My custom styles never show in Word editor.  Using trial version & MS Word for Mac 2011.  My test script is:

<?php
// Custom Style Headings with Table of Contents          
require_once 'classes/CreateDocx.inc';

define ('ORANGE', 'E06E1E');

// new report object
$docx = new CreateDocx();

// 2 Custom Heading Styles and 1 for normal text
$style1 = array('outlineLvl' => 1,
                    'jc' => 'left', 
                    'spacingBottom' => 100, 
                    'font' => 'Times New Roman', 
                    'bold' => true, 
                    'sz' => 16,
                    'color' => ORANGE);
$docx->createParagraphStyle('style1', $style1);

$style2 = array('outlineLvl' => 2,
                    'jc' => 'left', 
                    'spacingBottom' => 100, 
                    'font' => 'Times New Roman', 
                    'bold' => true, 
                    'sz' => 13,
                    'color' => ORANGE);
$docx->createParagraphStyle('style2', $style2);

$pLeftStyle = array('jc' => 'left', 'spacingBottom' => 100);
$docx->createParagraphStyle('pLeft', $pLeftStyle);

// Table of Contents

$tocOptions = array('autoUpdate' => false, 'displayLevels' => '1-2');
$tocLegend = array('text' => 'Update this Table of Contents using <control> click -> Update Field',
                    'pStyle' => 'pLeft',
                    'font' => 'Times New Roman');
                    
$docx->addText('Table of Contents', array('bold' => true, 'fontSize' => '14'));
$docx->addTableContents($tocOptions, $tocLegend);

// New Headings to include in the Table of Contents - 2 levels
$docx->addBreak(array('type'=>'page'));
$docx->addText('First Heading1', array('pStyle' => 'style1'));
$docx->addText('First Heading2', array('pStyle' => 'style2'));

// Paragraph 1
$text =  'This is the first paragraph.';
$docx->addText($text, $pLeft);

$docx->createDocx('trytoc');