Skip to content

Commit 248d82d

Browse files
committed
Add two recipes
1 parent f1eded7 commit 248d82d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

docs/recipes.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,42 @@
22

33
Recipes
44
=======
5+
6+
Create float left image
7+
-----------------------
8+
9+
Use absolute positioning relative to margin horizontally and to line
10+
vertically.
11+
12+
.. code-block:: php
13+
14+
$imageStyle = array(
15+
'width' => 40,
16+
'height' => 40
17+
'wrappingStyle' => 'square',
18+
'positioning' => 'absolute',
19+
'posHorizontalRel' => 'margin',
20+
'posVerticalRel' => 'line',
21+
);
22+
$textrun->addImage('resources/_earth.jpg', $imageStyle);
23+
$textrun->addText($lipsumText);
24+
25+
Download the produced file automatically
26+
----------------------------------------
27+
28+
Use ``php://output`` as the filename.
29+
30+
.. code-block:: php
31+
32+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
33+
$section = $phpWord->createSection();
34+
$section->addText('Hello World!');
35+
$file = 'HelloWorld.docx';
36+
header("Content-Description: File Transfer");
37+
header('Content-Disposition: attachment; filename="' . $file . '"');
38+
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
39+
header('Content-Transfer-Encoding: binary');
40+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
41+
header('Expires: 0');
42+
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
43+
$xmlWriter->save("php://output");

docs/src/documentation.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Don't forget to change `code::` directive to `code-block::` in the resulting rst
4040
- [RTF](#rtf)
4141
- [HTML](#html)
4242
- [PDF](#pdf)
43+
- [Recipes](#recipes)
4344
- [Frequently asked questions](#frequently-asked-questions)
4445
- [References](#references)
4546

@@ -929,6 +930,44 @@ To be completed.
929930

930931
To be completed.
931932

933+
# Recipes
934+
935+
## Create float left image
936+
937+
Use absolute positioning relative to margin horizontally and to line vertically.
938+
939+
```php
940+
$imageStyle = array(
941+
'width' => 40,
942+
'height' => 40
943+
'wrappingStyle' => 'square',
944+
'positioning' => 'absolute',
945+
'posHorizontalRel' => 'margin',
946+
'posVerticalRel' => 'line',
947+
);
948+
$textrun->addImage('resources/_earth.jpg', $imageStyle);
949+
$textrun->addText($lipsumText);
950+
```
951+
952+
## Download the produced file automatically
953+
954+
Use `php://output` as the filename.
955+
956+
```php
957+
$phpWord = new \PhpOffice\PhpWord\PhpWord();
958+
$section = $phpWord->createSection();
959+
$section->addText('Hello World!');
960+
$file = 'HelloWorld.docx';
961+
header("Content-Description: File Transfer");
962+
header('Content-Disposition: attachment; filename="' . $file . '"');
963+
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
964+
header('Content-Transfer-Encoding: binary');
965+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
966+
header('Expires: 0');
967+
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
968+
$xmlWriter->save("php://output");
969+
```
970+
932971
# Frequently asked questions
933972

934973
## Is this the same with PHPWord that I found in CodePlex?

0 commit comments

Comments
 (0)