Add two recipes

This commit is contained in:
Ivan Lanin 2014-05-24 10:53:09 +07:00
parent f1eded7b33
commit 248d82d3c3
2 changed files with 78 additions and 0 deletions

View File

@ -2,3 +2,42 @@
Recipes
=======
Create float left image
-----------------------
Use absolute positioning relative to margin horizontally and to line
vertically.
.. code-block:: php
$imageStyle = array(
'width' => 40,
'height' => 40
'wrappingStyle' => 'square',
'positioning' => 'absolute',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line',
);
$textrun->addImage('resources/_earth.jpg', $imageStyle);
$textrun->addText($lipsumText);
Download the produced file automatically
----------------------------------------
Use ``php://output`` as the filename.
.. code-block:: php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->createSection();
$section->addText('Hello World!');
$file = 'HelloWorld.docx';
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$xmlWriter->save("php://output");

View File

@ -40,6 +40,7 @@ Don't forget to change `code::` directive to `code-block::` in the resulting rst
- [RTF](#rtf)
- [HTML](#html)
- [PDF](#pdf)
- [Recipes](#recipes)
- [Frequently asked questions](#frequently-asked-questions)
- [References](#references)
@ -929,6 +930,44 @@ To be completed.
To be completed.
# Recipes
## Create float left image
Use absolute positioning relative to margin horizontally and to line vertically.
```php
$imageStyle = array(
'width' => 40,
'height' => 40
'wrappingStyle' => 'square',
'positioning' => 'absolute',
'posHorizontalRel' => 'margin',
'posVerticalRel' => 'line',
);
$textrun->addImage('resources/_earth.jpg', $imageStyle);
$textrun->addText($lipsumText);
```
## Download the produced file automatically
Use `php://output` as the filename.
```php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->createSection();
$section->addText('Hello World!');
$file = 'HelloWorld.docx';
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$xmlWriter->save("php://output");
```
# Frequently asked questions
## Is this the same with PHPWord that I found in CodePlex?