2 ini_set('include_path', __DIR__ . '/../../..:.');
3 require_once __DIR__ . '/../Writer.php';
6 $PHPWord = new Document_Word_Writer();
8 // New portrait section
9 $section = $PHPWord->createSection();
11 // Define the TOC font style
12 $fontStyle = array('spaceAfter'=>60, 'size'=>12);
15 $PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
16 $PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
19 $section->addText('Table of contents:');
20 $section->addTextBreak(2);
23 $section->addTOC($fontStyle);
26 $section->addPageBreak();
27 $section->addTitle('I am Title 1', 1);
28 $section->addText('Some text...');
29 $section->addTextBreak(2);
31 $section->addTitle('I am a Subtitle of Title 1', 2);
32 $section->addTextBreak(2);
33 $section->addText('Some more text...');
34 $section->addTextBreak(2);
36 $section->addTitle('Another Title (Title 2)', 1);
37 $section->addText('Some text...');
38 $section->addPageBreak();
39 $section->addTitle('I am Title 3', 1);
40 $section->addText('And more text...');
41 $section->addTextBreak(2);
42 $section->addTitle('I am a Subtitle of Title 3', 2);
43 $section->addText('Again and again, more text...');
45 echo 'Note: The pagenumbers in the TOC doesnt refresh automatically.';
48 require_once __DIR__ . '/../Writer/IOFactory.php';
49 $objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
50 $objWriter->save('/tmp/TitleTOC.docx');