|
1 | 1 | <?php
|
| 2 | +use PhpOffice\PhpWord\Element\Section; |
| 3 | +use PhpOffice\PhpWord\Shared\Converter; |
| 4 | + |
2 | 5 | include_once 'Sample_Header.php';
|
3 | 6 |
|
4 | 7 | // New Word document
|
|
9 | 12 | $section = $phpWord->addSection();
|
10 | 13 | $section->addText('Local image without any styles:');
|
11 | 14 | $section->addImage('resources/_mars.jpg');
|
12 |
| -$section->addTextBreak(2); |
13 | 15 |
|
| 16 | +printSeparator($section); |
14 | 17 | $section->addText('Local image with styles:');
|
15 | 18 | $section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
|
16 |
| -$section->addTextBreak(2); |
17 | 19 |
|
18 | 20 | // Remote image
|
| 21 | +printSeparator($section); |
19 | 22 | $source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
20 | 23 | $section->addText("Remote image from: {$source}");
|
21 | 24 | $section->addImage($source);
|
22 | 25 |
|
23 | 26 | // Image from string
|
| 27 | +printSeparator($section); |
24 | 28 | $source = 'resources/_mars.jpg';
|
25 | 29 | $fileContent = file_get_contents($source);
|
26 | 30 | $section->addText('Image from string');
|
27 | 31 | $section->addImage($fileContent);
|
28 | 32 |
|
29 | 33 | //Wrapping style
|
30 |
| -$text = str_repeat('Hello World! ', 15); |
| 34 | +printSeparator($section); |
| 35 | +$text = str_repeat('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ', 2); |
31 | 36 | $wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
32 | 37 | foreach ($wrappingStyles as $wrappingStyle) {
|
33 |
| - $section->addTextBreak(5); |
34 | 38 | $section->addText("Wrapping style {$wrappingStyle}");
|
35 | 39 | $section->addImage(
|
36 | 40 | 'resources/_earth.jpg',
|
37 | 41 | array(
|
38 |
| - 'positioning' => 'relative', |
39 |
| - 'marginTop' => -1, |
40 |
| - 'marginLeft' => 1, |
41 |
| - 'width' => 80, |
42 |
| - 'height' => 80, |
43 |
| - 'wrappingStyle' => $wrappingStyle, |
| 42 | + 'positioning' => 'relative', |
| 43 | + 'marginTop' => -1, |
| 44 | + 'marginLeft' => 1, |
| 45 | + 'width' => 80, |
| 46 | + 'height' => 80, |
| 47 | + 'wrappingStyle' => $wrappingStyle, |
| 48 | + 'wrapDistanceRight' => Converter::cmToPoint(1), |
| 49 | + 'wrapDistanceBottom' => Converter::cmToPoint(1), |
44 | 50 | )
|
45 | 51 | );
|
46 | 52 | $section->addText($text);
|
| 53 | + printSeparator($section); |
47 | 54 | }
|
48 | 55 |
|
49 | 56 | //Absolute positioning
|
50 |
| -$section->addTextBreak(3); |
51 | 57 | $section->addText('Absolute positioning: see top right corner of page');
|
52 | 58 | $section->addImage(
|
53 | 59 | 'resources/_mars.jpg',
|
|
64 | 70 | );
|
65 | 71 |
|
66 | 72 | //Relative positioning
|
67 |
| -$section->addTextBreak(3); |
| 73 | +printSeparator($section); |
68 | 74 | $section->addText('Relative positioning: Horizontal position center relative to column,');
|
69 | 75 | $section->addText('Vertical position top relative to line');
|
70 | 76 | $section->addImage(
|
|
80 | 86 | )
|
81 | 87 | );
|
82 | 88 |
|
| 89 | +function printSeparator(Section $section) |
| 90 | +{ |
| 91 | + $section->addTextBreak(); |
| 92 | + $lineStyle = array('weight' => 0.2, 'width' => 150, 'height' => 0, 'align' => 'center'); |
| 93 | + $section->addLine($lineStyle); |
| 94 | + $section->addTextBreak(2); |
| 95 | +} |
| 96 | + |
83 | 97 | // Save file
|
84 | 98 | echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
85 | 99 | if (!CLI) {
|
|
0 commit comments