Skip to content

Commit 277c2fb

Browse files
committed
Merge pull request #1 from PHPOffice/develop
Develop update from upstream
2 parents f18e51a + c44bd37 commit 277c2fb

17 files changed

+1068
-611
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.3.3
54
- 5.3
65
- 5.4
76
- 5.5
@@ -10,6 +9,7 @@ php:
109

1110
matrix:
1211
allow_failures:
12+
- php: 5.2
1313
- php: hhvm
1414

1515
env:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
2525
- Word2007 Writer : Support for RTL - @Progi1984 GH-331
2626
- MsDOC Reader: Basic MsDOC Reader - @Progi1984 GH-23 GH-287
2727
- "absolute" horizontal and vertical positioning of Frame - @basjan GH-302
28+
- Add new-page function for PDF generation. For multiple PDF-backends - @chc88 GH-426
2829

2930
### Bugfixes
3031

@@ -38,6 +39,7 @@ This release added form fields (textinput, checkbox, and dropdown), drawing shap
3839
- "addShape()" magic method in AbstractContainer is mistakenly named as "addObject()" - @GMTA GH-356
3940
- `Element\Section::setPageSizeW()` and `Element\Section::setPageSizeH()` were mentioned in the docs but not implemented.
4041
- Special Characters (ampersand) in Title break docx output - @RomanSyroeshko GH-401
42+
- `<th>` tag is closed with `</td>` tag: - @franzholz GH-438
4143

4244
### Deprecated
4345

README.md

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,51 +85,92 @@ require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
8585
The following is a basic usage example of the PHPWord library.
8686

8787
```php
88+
<?php
8889
require_once 'src/PhpWord/Autoloader.php';
8990
\PhpOffice\PhpWord\Autoloader::register();
9091

92+
// Creating the new document...
9193
$phpWord = new \PhpOffice\PhpWord\PhpWord();
9294

93-
// Every element you want to append to the word document is placed in a section.
94-
// To create a basic section:
95+
/* Note: any element you append to a document must reside inside of a Section. */
96+
97+
// Adding an empty Section to the document...
9598
$section = $phpWord->addSection();
99+
// Adding Text element to the Section having font styled by default...
100+
$section->addText(
101+
htmlspecialchars(
102+
'"Learn from yesterday, live for today, hope for tomorrow. '
103+
. 'The important thing is not to stop questioning." '
104+
. '(Albert Einstein)'
105+
)
106+
);
107+
108+
/*
109+
* Note: it's possible to customize font style of the Text element you add in three ways:
110+
* - inline;
111+
* - using named font style (new font style object will be implicitly created);
112+
* - using explicitly created font style object.
113+
*/
114+
115+
// Adding Text element with font customized inline...
116+
$section->addText(
117+
htmlspecialchars(
118+
'"Great achievement is usually born of great sacrifice, '
119+
. 'and is never the result of selfishness." '
120+
. '(Napoleon Hill)'
121+
),
122+
array('name' => 'Tahoma', 'size' => 10)
123+
);
124+
125+
// Adding Text element with font customized using named font style...
126+
$fontStyleName = 'oneUserDefinedStyle';
127+
$phpWord->addFontStyle(
128+
$fontStyleName,
129+
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
130+
);
131+
$section->addText(
132+
htmlspecialchars(
133+
'"The greatest accomplishment is not in never falling, '
134+
. 'but in rising again after you fall." '
135+
. '(Vince Lombardi)'
136+
),
137+
$fontStyleName
138+
);
96139

97-
// After creating a section, you can append elements:
98-
$section->addText('Hello world!');
99-
100-
// You can directly style your text by giving the addText function an array:
101-
$section->addText('Hello world! I am formatted.',
102-
array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
103-
104-
// If you often need the same style again you can create a user defined style
105-
// to the word document and give the addText function the name of the style:
106-
$phpWord->addFontStyle('myOwnStyle',
107-
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
108-
$section->addText('Hello world! I am formatted by a user defined style',
109-
'myOwnStyle');
110-
111-
// You can also put the appended element to local object like this:
112-
$fontStyle = array(
113-
'name' => 'Verdana',
114-
'size' => 22,
115-
'bold' => true,
140+
// Adding Text element with font customized using explicitly created font style object...
141+
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
142+
$fontStyle->setBold(true);
143+
$fontStyle->setName('Tahoma');
144+
$fontStyle->setSize(13);
145+
$myTextElement = $section->addText(
146+
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
116147
);
117-
$myTextElement = $section->addText('Hello World!');
118148
$myTextElement->setFontStyle($fontStyle);
119149

120-
// Finally, save the document:
121-
$phpWord->save('helloWorld.docx');
122-
$phpWord->save('helloWorld.odt', 'ODText');
123-
$phpWord->save('helloWorld.rtf', 'RTF');
150+
// Saving the document as OOXML file...
151+
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
152+
$objWriter->save('helloWorld.docx');
153+
154+
// Saving the document as ODF file...
155+
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
156+
$objWriter->save('helloWorld.odt');
157+
158+
// Saving the document as HTML file...
159+
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
160+
$objWriter->save('helloWorld.html');
161+
162+
/* Note: we skip RTF, because it's not XML-based and requires a different example. */
163+
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */
124164
```
165+
:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken.
125166

126167
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.
127168

128169
## Contributing
129170

130-
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute:
171+
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.
131172

132-
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md)
133-
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch
134-
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub
135-
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter
173+
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md).
174+
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch.
175+
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub.
176+
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter.

0 commit comments

Comments
 (0)