add exmpales
[pear-examples] / Document_Word_Writer / Examples / Image.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 image elements
12 //$section->addImage('_mars.jpg');
13 //$section->addTextBreak(2);
14 $section->addText('Below is earth image!'); 
15 $section->addTextBreak(2);
16 $section->addImage('_earth.JPG', array('width'=>500, 'height'=>500));
17 $section->addTextBreak(2);
18 $section->addText('Above is earth image!');
19 //$section->addImage('_mars.jpg');
20
21 // add in /tmp/67219.0.jpg
22 //$rid = $section->addImageDefered('_earth.JPG', array('width'=>210, 'height'=>210, 'align'=>'center'));
23 // store map [67219.0] = $rid
24
25 // when get image - > lookup map [67219.0] for rid
26 //$section->addImageToCollection($rid, '_earth.JPG'); // 67219.0.jpg/:;:
27 $fn = '/tmp/Image.docx';
28 // Save File
29 require_once __DIR__ . '/../Writer/IOFactory.php';
30 $objWriter = Document_Word_Writer_IOFactory::createWriter($PHPWord, 'Word2007');
31 $objWriter->save($fn);
32 // Download the file for testing
33 if($_SERVER['SERVER_NAME'] == 'localhost')
34 {
35     exit;
36 }
37 if (file_exists($fn)) {
38     echo 'Prepare for download!!';
39     header('Content-Description: File Transfer');
40     header('Content-Type: application/octet-stream');
41     header('Content-Disposition: attachment; filename='.basename($fn));
42     header('Content-Transfer-Encoding: binary');
43     header('Expires: 0');
44     header('Cache-Control: must-revalidate');
45     header('Pragma: public');
46     header('Content-Length: ' . filesize($fn));
47     ob_clean();
48     flush();
49     readfile($fn);
50     exit;
51 }
52 ?>