add exmpales
[pear-examples] / Document_Word_Writer / Examples / TitleTOC.php
diff --git a/Document_Word_Writer/Examples/TitleTOC.php b/Document_Word_Writer/Examples/TitleTOC.php
new file mode 100644 (file)
index 0000000..94922c1
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+ini_set('include_path', __DIR__  . '/../../..:.');
+require_once __DIR__ . '/../Writer.php';
+
+// New Word Document
+$PHPWord = new Document_Word_Writer();
+
+// New portrait section
+$section = $PHPWord->createSection();
+
+// Define the TOC font style
+$fontStyle = array('spaceAfter'=>60, 'size'=>12);
+
+// Add title styles
+$PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
+$PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
+
+// Add text elements
+$section->addText('Table of contents:');
+$section->addTextBreak(2);
+
+// Add TOC
+$section->addTOC($fontStyle);
+
+// Add Titles
+$section->addPageBreak();
+$section->addTitle('I am Title 1', 1);
+$section->addText('Some text...');
+$section->addTextBreak(2);
+
+$section->addTitle('I am a Subtitle of Title 1', 2);
+$section->addTextBreak(2);
+$section->addText('Some more text...');
+$section->addTextBreak(2);
+
+$section->addTitle('Another Title (Title 2)', 1);
+$section->addText('Some text...');
+$section->addPageBreak();
+$section->addTitle('I am Title 3', 1);
+$section->addText('And more text...');
+$section->addTextBreak(2);
+$section->addTitle('I am a Subtitle of Title 3', 2);
+$section->addText('Again and again, more text...');
+
+echo 'Note: The pagenumbers in the TOC doesnt refresh automatically.';
+
+// Save File
+require_once __DIR__ . '/../Writer/IOFactory.php';
+$objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
+$objWriter->save('/tmp/TitleTOC.docx');
+?>