|
| 1 | +<?php |
| 2 | + |
| 3 | +use PhpOffice\PhpWord\Style\Font; |
| 4 | + |
| 5 | +define('USE_AUTOLOADER', true); |
| 6 | + |
| 7 | +include_once 'Sample_Header.php'; |
| 8 | + |
| 9 | +// New Word Document |
| 10 | +echo date('H:i:s') , ' Create new PhpWord object' , EOL; |
| 11 | + |
| 12 | +$languageEnGb = new PhpOffice\PhpWord\Style\Language(PhpOffice\PhpWord\Style\Language::EN_GB); |
| 13 | + |
| 14 | +$phpWord = new PhpOffice\PhpWord\PhpWord(); |
| 15 | +$phpWord->getSettings()->setThemeFontLang($languageEnGb); |
| 16 | + |
| 17 | +$fontStyleName = 'rStyle'; |
| 18 | +$phpWord->addFontStyle($fontStyleName, ['bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true]); |
| 19 | + |
| 20 | +$paragraphStyleName = 'pStyle'; |
| 21 | +$phpWord->addParagraphStyle($paragraphStyleName, ['alignment' => PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100]); |
| 22 | + |
| 23 | +$phpWord->addTitleStyle(1, ['bold' => true], ['spaceAfter' => 240]); |
| 24 | + |
| 25 | +// New portrait section |
| 26 | +$section = $phpWord->addSection(); |
| 27 | + |
| 28 | +// Simple text |
| 29 | +$section->addTitle('Welcome to PhpWord', 1); |
| 30 | +$section->addText('Hello World!'); |
| 31 | + |
| 32 | +// $pStyle = new Font(); |
| 33 | +// $pStyle->setLang() |
| 34 | +$section->addText('Ce texte-ci est en français.', ['lang' => PhpOffice\PhpWord\Style\Language::FR_BE]); |
| 35 | + |
| 36 | +// Two text break |
| 37 | +$section->addTextBreak(2); |
| 38 | + |
| 39 | +// Define styles |
| 40 | +$section->addText('I am styled by a font style definition.', $fontStyleName); |
| 41 | +$section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName); |
| 42 | +$section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName); |
| 43 | + |
| 44 | +$section->addTextBreak(); |
| 45 | + |
| 46 | +// Inline font style |
| 47 | +$fontStyle['name'] = 'Times New Roman'; |
| 48 | +$fontStyle['size'] = 20; |
| 49 | + |
| 50 | +$textrun = $section->addTextRun(); |
| 51 | +$textrun->addText('I am inline styled ', $fontStyle); |
| 52 | +$textrun->addText('with '); |
| 53 | +$textrun->addText('color', ['color' => '996699']); |
| 54 | +$textrun->addText(', '); |
| 55 | +$textrun->addText('bold', ['bold' => true]); |
| 56 | +$textrun->addText(', '); |
| 57 | +$textrun->addText('italic', ['italic' => true]); |
| 58 | +$textrun->addText(', '); |
| 59 | +$textrun->addText('underline', ['underline' => 'dash']); |
| 60 | +$textrun->addText(', '); |
| 61 | +$textrun->addText('strikethrough', ['strikethrough' => true]); |
| 62 | +$textrun->addText(', '); |
| 63 | +$textrun->addText('doubleStrikethrough', ['doubleStrikethrough' => true]); |
| 64 | +$textrun->addText(', '); |
| 65 | +$textrun->addText('superScript', ['superScript' => true]); |
| 66 | +$textrun->addText(', '); |
| 67 | +$textrun->addText('subScript', ['subScript' => true]); |
| 68 | +$textrun->addText(', '); |
| 69 | +$textrun->addText('smallCaps', ['smallCaps' => true]); |
| 70 | +$textrun->addText(', '); |
| 71 | +$textrun->addText('allCaps', ['allCaps' => true]); |
| 72 | +$textrun->addText(', '); |
| 73 | +$textrun->addText('fgColor', ['fgColor' => 'yellow']); |
| 74 | +$textrun->addText(', '); |
| 75 | +$textrun->addText('scale', ['scale' => 200]); |
| 76 | +$textrun->addText(', '); |
| 77 | +$textrun->addText('spacing', ['spacing' => 120]); |
| 78 | +$textrun->addText(', '); |
| 79 | +$textrun->addText('kerning', ['kerning' => 10]); |
| 80 | +$textrun->addText('. '); |
| 81 | + |
| 82 | +// Link |
| 83 | +$section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); |
| 84 | +$section->addTextBreak(); |
| 85 | + |
| 86 | +// Image |
| 87 | +$section->addImage(__DIR__ . '/resources/_earth.jpg', ['width' => 18, 'height' => 18]); |
| 88 | + |
| 89 | +// Save file |
| 90 | +echo write($phpWord, basename(__FILE__, '.php'), $writers); |
| 91 | +if (!CLI) { |
| 92 | + include_once 'Sample_Footer.php'; |
| 93 | +} |
0 commit comments