From 1ec0589c557406725bf03eb0f791b6f8002a06a3 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Sun, 8 Jun 2014 22:38:50 +0700 Subject: [PATCH] Update basic example --- README.md | 18 ++++++++++++------ docs/general.rst | 9 +++++---- docs/src/documentation.md | 9 +++++---- src/PhpWord/PhpWord.php | 1 + 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a9006f2c..97e5b642 100644 --- a/README.md +++ b/README.md @@ -67,11 +67,14 @@ require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); ``` -## Usages +## Getting started -The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/). +The following is a basic usage example of the PHPWord library. ```php +require_once 'src/PhpWord/Autoloader.php'; +\PhpOffice\PhpWord\Autoloader::register(); + $phpWord = new \PhpOffice\PhpWord\PhpWord(); // Every element you want to append to the word document is placed in a section. @@ -93,10 +96,11 @@ $section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); // You can also put the appended element to local object like this: -$fontStyle = new \PhpOffice\PhpWord\Style\Font(); -$fontStyle->setBold(true); -$fontStyle->setName('Verdana'); -$fontStyle->setSize(22); +$fontStyle = array( + 'name' => 'Verdana', + 'size' => 22, + 'bold' => true, +); $myTextElement = $section->addText('Hello World!'); $myTextElement->setFontStyle($fontStyle); @@ -106,6 +110,8 @@ $phpWord->save('helloWorld.odt', 'ODText'); $phpWord->save('helloWorld.rtf', 'RTF'); ``` +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/develop/) for more detail. + ## Known issues - GH-238: PHPWord uses temporary folder with `sys_get_temp_dir()` extensively. The default setting on some systems (especially Windows) do not give appropriate read/write permission to this folder. Run `samples/index.php` either by CLI or by web browsers to check if you have this requirement fulfilled. diff --git a/docs/general.rst b/docs/general.rst index 0bbeb2ec..60d9b609 100644 --- a/docs/general.rst +++ b/docs/general.rst @@ -36,10 +36,11 @@ folder `__. 'myOwnStyle'); // You can also put the appended element to local object like this: - $fontStyle = new \PhpOffice\PhpWord\Style\Font(); - $fontStyle->setBold(true); - $fontStyle->setName('Verdana'); - $fontStyle->setSize(22); + $fontStyle = array( + 'name' => 'Verdana', + 'size' => 22, + 'bold' => true, + ); $myTextElement = $section->addText('Hello World!'); $myTextElement->setFontStyle($fontStyle); diff --git a/docs/src/documentation.md b/docs/src/documentation.md index c2fc5e77..144222c1 100644 --- a/docs/src/documentation.md +++ b/docs/src/documentation.md @@ -231,10 +231,11 @@ $section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); // You can also put the appended element to local object like this: -$fontStyle = new \PhpOffice\PhpWord\Style\Font(); -$fontStyle->setBold(true); -$fontStyle->setName('Verdana'); -$fontStyle->setSize(22); +$fontStyle = array( + 'name' => 'Verdana', + 'size' => 22, + 'bold' => true, +); $myTextElement = $section->addText('Hello World!'); $myTextElement->setFontStyle($fontStyle); diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index 8e889cce..c8ed568c 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -280,6 +280,7 @@ class PhpWord 'PDF' => 'application/pdf', ); + /** @var \PhpOffice\PhpWord\Writer\WriterInterface $writer */ $writer = IOFactory::createWriter($this, $format); if ($download === true) {