@@ -101,8 +101,13 @@ The following is a basic usage example of the PHPWord library.
101101<?php
102102require_once 'bootstrap.php';
103103
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+
104109// Creating the new document...
105- $phpWord = new \PhpOffice\PhpWord\ PhpWord();
110+ $phpWord = new PhpWord();
106111
107112/* Note: any element you append to a document must reside inside of a Section. */
108113
@@ -127,14 +132,14 @@ $section->addText(
127132 '"Great achievement is usually born of great sacrifice, '
128133 . 'and is never the result of selfishness." '
129134 . '(Napoleon Hill)',
130- array('name' => 'Tahoma', 'size' => 10 )
135+ array('name' => 'Tahoma', 'size' => Absolute::from('pt', 10) )
131136);
132137
133138// Adding Text element with font customized using named font style...
134139$fontStyleName = 'oneUserDefinedStyle';
135140$phpWord->addFontStyle(
136141 $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)
138143);
139144$section->addText(
140145 '"The greatest accomplishment is not in never falling, '
@@ -144,10 +149,10 @@ $section->addText(
144149);
145150
146151// Adding Text element with font customized using explicitly created font style object...
147- $fontStyle = new \PhpOffice\PhpWord\Style\ Font();
152+ $fontStyle = new Font();
148153$fontStyle->setBold(true);
149154$fontStyle->setName('Tahoma');
150- $fontStyle->setSize(13 );
155+ $fontStyle->setSize(Absolute::from('pt', 13) );
151156$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
152157$myTextElement->setFontStyle($fontStyle);
153158
0 commit comments