@@ -101,8 +101,13 @@ The following is a basic usage example of the PHPWord library.
101
101
<?php
102
102
require_once 'bootstrap.php';
103
103
104
+ use PhpOffice\PhpWord\PhpWord;
105
+ use PhpOffice\PhpWord\Style\Font;
106
+ use PhpOffice\PhpWord\Style\Colors\Hex;
107
+ use PhpOffice\PhpWord\Style\Lengths\Absolute;
108
+
104
109
// Creating the new document...
105
- $phpWord = new \PhpOffice\PhpWord\ PhpWord();
110
+ $phpWord = new PhpWord();
106
111
107
112
/* Note: any element you append to a document must reside inside of a Section. */
108
113
@@ -127,14 +132,14 @@ $section->addText(
127
132
'"Great achievement is usually born of great sacrifice, '
128
133
. 'and is never the result of selfishness." '
129
134
. '(Napoleon Hill)',
130
- array('name' => 'Tahoma', 'size' => 10 )
135
+ array('name' => 'Tahoma', 'size' => Absolute::from('pt', 10) )
131
136
);
132
137
133
138
// Adding Text element with font customized using named font style...
134
139
$fontStyleName = 'oneUserDefinedStyle';
135
140
$phpWord->addFontStyle(
136
141
$fontStyleName,
137
- array('name' => 'Tahoma', 'size' => 10 , 'color' => '1B2232', 'bold' => true)
142
+ array('name' => 'Tahoma', 'size' => Absolute::from('pt', 10) , 'color' => new Hex( '1B2232') , 'bold' => true)
138
143
);
139
144
$section->addText(
140
145
'"The greatest accomplishment is not in never falling, '
@@ -144,10 +149,10 @@ $section->addText(
144
149
);
145
150
146
151
// Adding Text element with font customized using explicitly created font style object...
147
- $fontStyle = new \PhpOffice\PhpWord\Style\ Font();
152
+ $fontStyle = new Font();
148
153
$fontStyle->setBold(true);
149
154
$fontStyle->setName('Tahoma');
150
- $fontStyle->setSize(13 );
155
+ $fontStyle->setSize(Absolute::from('pt', 13) );
151
156
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
152
157
$myTextElement->setFontStyle($fontStyle);
153
158
0 commit comments