add exmpales
[pear-examples] / Document_Word_Writer / Examples / TitleTOC.php
1 <?php
2 ini_set('include_path', __DIR__  . '/../../..:.');
3 require_once __DIR__ . '/../Writer.php';
4
5 // New Word Document
6 $PHPWord = new Document_Word_Writer();
7
8 // New portrait section
9 $section = $PHPWord->createSection();
10
11 // Define the TOC font style
12 $fontStyle = array('spaceAfter'=>60, 'size'=>12);
13
14 // Add title styles
15 $PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
16 $PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
17
18 // Add text elements
19 $section->addText('Table of contents:');
20 $section->addTextBreak(2);
21
22 // Add TOC
23 $section->addTOC($fontStyle);
24
25 // Add Titles
26 $section->addPageBreak();
27 $section->addTitle('I am Title 1', 1);
28 $section->addText('Some text...');
29 $section->addTextBreak(2);
30
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);
35
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...');
44
45 echo 'Note: The pagenumbers in the TOC doesnt refresh automatically.';
46
47 // Save File
48 require_once __DIR__ . '/../Writer/IOFactory.php';
49 $objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
50 $objWriter->save('/tmp/TitleTOC.docx');
51 ?>