add exmpales
[pear-examples] / Document_Word_Writer / Examples / HeaderFooter.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 // Add header
12 $header = $section->createHeader();
13 $table = $header->addTable();
14 $table->addRow();
15 $table->addCell(3000)->addText('This is the header.', array('align'=>'right') , array('align'=>'right'));
16 $table->addCell(5000)->addImage('_earth.JPG', array('width'=>50, 'height'=>50, 'align'=>'right'));
17
18 // Add footer
19 $footer = $section->createFooter();
20 $footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align'=>'right'));
21
22 // Write some text
23 $section->addTextBreak();
24 $section->addText('Some text...');
25
26 // Save File
27 require_once __DIR__ . '/../Writer/IOFactory.php';
28 $objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
29 $objWriter->save('/tmp/HeaderFooter.docx');
30 $fn = '/tmp/HeaderFooter.docx';
31 if (file_exists($fn)) {
32     echo 'Prepare for download!!';
33     header('Content-Description: File Transfer');
34     header('Content-Type: application/octet-stream');
35     header('Content-Disposition: attachment; filename='.basename($fn));
36     header('Content-Transfer-Encoding: binary');
37     header('Expires: 0');
38     header('Cache-Control: must-revalidate');
39     header('Pragma: public');
40     header('Content-Length: ' . filesize($fn));
41     ob_clean();
42     flush();
43     readfile($fn);
44     exit;
45 }
46 ?>