You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Note: RTF was skipped here, because the format is not XML-based and requires a bit different example. */
146
+
/* Note: PDF was skipped here, because we use "HTML-to-PDF" approach to create PDF documents. */
124
147
```
125
-
:warning: Escape any string you pass to your document, otherwise it may get broken.
148
+
:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken.
126
149
127
150
More examples are provided in the [samples folder](samples/). You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/) for more detail.
Copy file name to clipboardExpand all lines: docs/src/documentation.md
+49-26Lines changed: 49 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -212,42 +212,65 @@ After installation, you can browse and use the samples that we've provided, eith
212
212
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](https://github.com/PHPOffice/PHPWord/tree/master/samples/).
213
213
214
214
```php
215
+
<?php
215
216
require_once 'src/PhpWord/Autoloader.php';
216
217
\PhpOffice\PhpWord\Autoloader::register();
217
218
219
+
// Creating the new document...
218
220
$phpWord = new \PhpOffice\PhpWord\PhpWord();
219
221
220
-
// Every element you want to append to the word document is placed in a section.
221
-
// To create a basic section:
222
+
/* Note: any element you append to a document must reside inside of a Section. */
223
+
224
+
// Adding an empty Section to the document...
222
225
$section = $phpWord->addSection();
226
+
// Adding Text element to the Section having font styled by default...
227
+
$section->addText(
228
+
htmlspecialchars('"Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning." (Albert Einstein)')
229
+
);
230
+
231
+
/*
232
+
* Note: it is possible to customize font style of the Text element you add in three ways:
233
+
* - inline;
234
+
* - using named font style (new font style object will be implicitly created);
235
+
* - using explicitly created font style object.
236
+
*/
237
+
238
+
// Adding Text element having font customized inline...
239
+
$section->addText(
240
+
htmlspecialchars('"Great achievement is usually born of great sacrifice, and is never the result of selfishness." (Napoleon Hill)'),
241
+
array('name' => 'Tahoma', 'size' => 10)
242
+
);
223
243
224
-
// After creating a section, you can append elements:
225
-
$section->addText('Hello world!');
226
-
227
-
// You can directly style your text by giving the addText function an array:
0 commit comments