diff --git a/.gitignore b/.gitignore
index 2ea4fd9d..eb0f0679 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,13 +4,12 @@
.Trashes
Thumbs.db
Desktop.ini
-.idea
-_build
-phpunit.xml
composer.lock
composer.phar
-vendor
-/report
-/.settings
+phpunit.xml
/.buildpath
-/.project
\ No newline at end of file
+/.idea
+/.project
+/.settings
+/build
+/vendor
diff --git a/.travis.yml b/.travis.yml
index 8ed7a45f..ad3df613 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,8 +18,9 @@ before_script:
## Composer
# - curl -s http://getcomposer.org/installer | php
# - php composer.phar install --prefer-source
+ - composer self-update
+ - composer require dompdf/dompdf:0.6.*
- composer install --prefer-source
- - composer selfupdate --quiet
## PHP_CodeSniffer
- pyrus install pear/PHP_CodeSniffer
- phpenv rehash
@@ -37,7 +38,7 @@ before_script:
script:
## PHP_CodeSniffer
- - phpcs --standard=PSR2 -n src/
+ - phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip
- phpcs --standard=PSR2 -n tests/
## PHP Copy/Paste Detector
#- php phpcpd.phar --verbose src/
diff --git a/CHANGELOG.md b/CHANGELOG.md
old mode 100755
new mode 100644
index 3bb699ea..e23edf91
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,92 @@
This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub.
+## 0.10.0 - Not yet released
+
+This release marked heavy refactorings on internal code structure with the creation of some abstract classes to reduce code duplication. `Element` subnamespace is introduced in this release to replace `Section`. Word2007 reader capability is greatly enhanced. Endnote is introduced. List numbering is now customizable. Basic HTML and PDF writing support is enabled. Basic ODText reader is introduced.
+
+### Features
+
+- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
+- Table: Add `tblGrid` element for Libre/Open Office table sizing - @gianis6 GH-183
+- Footnote: Ability to insert textbreak in footnote `$footnote->addTextBreak()` - @ivanlanin
+- Footnote: Ability to style footnote reference mark by using `FootnoteReference` style - @ivanlanin
+- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
+- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
+- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
+- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin GH-106 GH-140 GH-185
+- Template: Ability to find & replace variables in headers & footers - @dgudgeon GH-190
+- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira GH-191
+- TOC: Ability to have two or more TOC in one document and to set min and max depth for TOC - @Pyreweb GH-189
+- Table: Ability to add footnote in table cell - @ivanlanin GH-187
+- Footnote: Ability to add image in footnote - @ivanlanin GH-187
+- ListItem: Ability to add list item in header/footer - @ivanlanin GH-187
+- CheckBox: Ability to add checkbox in header/footer - @ivanlanin GH-187
+- Link: Ability to add link in header/footer - @ivanlanin GH-187
+- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
+- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
+- General: Add `Style::resetStyles()`, `Footnote::resetElements()`, and `TOC::resetTitles()` - @ivanlanin GH-187
+- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
+- Endnote: Ability to add endnotes - @ivanlanin
+- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
+- ODT Writer: Basic table writing support - @ivanlanin
+- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
+- HTML Writer: Basic HTML writer: text, textrun, link, title, textbreak, table, image (as Base64), footnote, endnote - @ivanlanin GH-203 GH-67 GH-147
+- PDF Writer: Basic PDF writer using DomPDF: All HTML element except image - @ivanlanin GH-68
+- DOCX Writer: Change `docProps/app.xml` `Application` to `PHPWord` - @ivanlanin
+- DOCX Writer: Create `word/settings.xml` and `word/webSettings.xml` dynamically - @ivanlanin
+- ODT Writer: Basic image writing - @ivanlanin
+- ODT Writer: Link writing - @ivanlanin
+- ODT Reader: Basic ODText Reader - @ivanlanin GH-71
+- Section: Ability to define gutter and line numbering - @ivanlanin
+- Font: Small caps, all caps, and double strikethrough - @ivanlanin GH-151
+- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin GH-199
+- Style: Remove `bgColor` from `Font`, `Table`, and `Cell` and put it into the new `Shading` style - @ivanlanin
+- Style: New `Indentation` and `Spacing` style - @ivanlanin
+- Paragraph: Ability to define first line and right indentation - @ivanlanin
+
+### Bugfixes
+
+- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
+- Documentation: Error in a function - @theBeerNut GH-195
+
+### Deprecated
+
+- `createTextRun` replaced by `addTextRun`
+- `createFootnote` replaced by `addFootnote`
+- `createHeader` replaced by `addHeader`
+- `createFooter` replaced by `addFooter`
+- `createSection` replaced by `addSection`
+- `Element\Footnote::getReferenceId` replaced by `Element\AbstractElement::getRelationId`
+- `Element\Footnote::setReferenceId` replaced by `Element\AbstractElement::setRelationId`
+- `Footnote::addFootnoteLinkElement` replaced by `Media::addElement`
+- `Footnote::getFootnoteLinkElements` replaced by `Media::getElements`
+- All current methods on `Media`
+- `Element\Link::getLinkSrc` replaced by `Element\Link::getTarget`
+- `Element\Link::getLinkName` replaced by `Element\Link::getText`
+- `Style\Cell::getDefaultBorderColor`
+
+### Miscellaneous
+
+- Documentation: Simplify page level docblock - @ivanlanin GH-179
+- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
+- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
+- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
+- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
+- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
+- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
+- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
+- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
+- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
+- Writer: New 'ODText\Base` class - @ivanlanin GH-187
+- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
+- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
+- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
+- Refactor: Remove Style\Tabs - @ivanlanin
+- Refactor: Apply composite pattern for writers - @ivanlanin
+- Refactor: Split `AbstractContainer` from `AbstractElement` - @ivanlanin
+- Refactor: Apply composite pattern for Word2007 reader - @ivanlanin
+
## 0.9.1 - 27 Mar 2014
This is a bugfix release for PSR-4 compatibility.
diff --git a/license.md b/LICENSE.md
similarity index 100%
rename from license.md
rename to LICENSE.md
diff --git a/README.md b/README.md
old mode 100755
new mode 100644
index 91ddbebf..5a8db0ef
--- a/README.md
+++ b/README.md
@@ -1,111 +1,112 @@
-# 
-
-[](https://travis-ci.org/PHPOffice/PHPWord)
-[](https://packagist.org/packages/phpoffice/phpword)
-[](https://packagist.org/packages/phpoffice/phpword)
-[](https://packagist.org/packages/phpoffice/phpword)
-[](https://packagist.org/packages/phpoffice/phpword)
-
-
-PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF).
-
-With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
-
-* Set document properties, e.g. title, subject, and creator.
-* Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
-* Create header and footer for each sections
-* Set default font type, font size, and paragraph style
-* Use UTF-8 and East Asia fonts/characters
-* Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text
-* Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
-* Insert titles (headers) and table of contents
-* Insert text breaks and page breaks
-* Insert and format images, either local, remote, or as page watermarks
-* Insert binary OLE Objects such as Excel or Visio
-* Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan)
-* Insert list items as bulleted, numbered, or multilevel
-* Insert hyperlinks
-* Create document from templates
-* Use XSL 1.0 style sheets to transform main document part of OOXML template
-* ... and many more features on progress
-
-__Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us.
-
-## Requirements
-* PHP 5.3+
-* PHP [Zip](http://php.net/manual/en/book.zip.php) extension
-* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension
-
-### Optional PHP extensions
-* PHP [GD](http://php.net/manual/en/book.image.php) extension
-* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension
-* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension
-
-## Installation
-
-It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add
-the following lines to your ``composer.json``.
-
-```json
-{
- "require": {
- "phpoffice/phpword": "dev-master"
- }
-}
-```
-
-Alternatively, you can download the latest release from the [releases page](https://github.com/PHPOffice/PHPWord/releases).
-In this case, you will have to register the autoloader.
-
-```php
-require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
-PhpOffice\PhpWord\Autoloader::register();
-```
-
-## Basic usage
-
-The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
-
-```php
-$phpWord = new \PhpOffice\PhpWord\PhpWord();
-
-// Every element you want to append to the word document is placed in a section.
-// To create a basic section:
-$section = $phpWord->createSection();
-
-// After creating a section, you can append elements:
-$section->addText('Hello world!');
-
-// You can directly style your text by giving the addText function an array:
-$section->addText('Hello world! I am formatted.',
- array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
-
-// If you often need the same style again you can create a user defined style
-// to the word document and give the addText function the name of the style:
-$phpWord->addFontStyle('myOwnStyle',
- array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
-$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);
-$myTextElement = $section->addText('Hello World!');
-$myTextElement->setFontStyle($fontStyle);
-
-// Finally, write the document:
-$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
-$objWriter->save('helloWorld.docx');
-
-$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
-$objWriter->save('helloWorld.odt');
-
-$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
-$objWriter->save('helloWorld.rtf');
-```
-
-## Documentation
-
-__Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/).
+# 
+
+[](https://travis-ci.org/PHPOffice/PHPWord)
+[](https://packagist.org/packages/phpoffice/phpword)
+[](https://packagist.org/packages/phpoffice/phpword)
+[](https://packagist.org/packages/phpoffice/phpword)
+[](https://packagist.org/packages/phpoffice/phpword)
+
+
+PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF).
+
+With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
+
+* Set document properties, e.g. title, subject, and creator.
+* Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
+* Create header and footer for each sections
+* Set default font type, font size, and paragraph style
+* Use UTF-8 and East Asia fonts/characters
+* Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text
+* Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
+* Insert titles (headers) and table of contents
+* Insert text breaks and page breaks
+* Insert and format images, either local, remote, or as page watermarks
+* Insert binary OLE Objects such as Excel or Visio
+* Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan)
+* Insert list items as bulleted, numbered, or multilevel
+* Insert hyperlinks
+* Insert footnotes and endnotes
+* Create document from templates
+* Use XSL 1.0 style sheets to transform main document part of OOXML template
+* ... and many more features on progress
+
+__Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us.
+
+## Requirements
+* PHP 5.3+
+* PHP [Zip](http://php.net/manual/en/book.zip.php) extension
+* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension
+
+### Optional PHP extensions
+* PHP [GD](http://php.net/manual/en/book.image.php) extension
+* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension
+* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension
+
+## Installation
+
+It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add
+the following lines to your ``composer.json``.
+
+```json
+{
+ "require": {
+ "phpoffice/phpword": "dev-master"
+ }
+}
+```
+
+Alternatively, you can download the latest release from the [releases page](https://github.com/PHPOffice/PHPWord/releases).
+In this case, you will have to register the autoloader.
+
+```php
+require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
+\PhpOffice\PhpWord\Autoloader::register();
+```
+
+## Basic usage
+
+The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
+
+```php
+$phpWord = new \PhpOffice\PhpWord\PhpWord();
+
+// Every element you want to append to the word document is placed in a section.
+// To create a basic section:
+$section = $phpWord->addSection();
+
+// After creating a section, you can append elements:
+$section->addText('Hello world!');
+
+// You can directly style your text by giving the addText function an array:
+$section->addText('Hello world! I am formatted.',
+ array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
+
+// If you often need the same style again you can create a user defined style
+// to the word document and give the addText function the name of the style:
+$phpWord->addFontStyle('myOwnStyle',
+ array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
+$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);
+$myTextElement = $section->addText('Hello World!');
+$myTextElement->setFontStyle($fontStyle);
+
+// Finally, write the document:
+$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
+$objWriter->save('helloWorld.docx');
+
+$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
+$objWriter->save('helloWorld.odt');
+
+$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
+$objWriter->save('helloWorld.rtf');
+```
+
+## Documentation
+
+__Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/).
diff --git a/composer.json b/composer.json
index fcca56e7..fafa9a28 100644
--- a/composer.json
+++ b/composer.json
@@ -8,7 +8,7 @@
],
"homepage": "http://phpoffice.github.io",
"type": "library",
- "license": "LGPL-3.0+",
+ "license": "LGPL-2.1+",
"authors": [
{
"name": "Mark Baker"
@@ -25,6 +25,10 @@
{
"name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org"
+ },
+ {
+ "name": "Roman Syroeshko",
+ "homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
}
],
"require": {
@@ -36,9 +40,10 @@
"phpunit/phpunit": "3.7.*"
},
"suggest": {
- "ext-gd2": "*",
- "ext-xmlwriter": "*",
- "ext-xsl": "*"
+ "ext-gd2": "Required to add images",
+ "ext-xmlwriter": "Required to write DOCX and ODT",
+ "ext-xsl": "Required to apply XSL style sheet to template part",
+ "dompdf/dompdf": "Required to write PDF"
},
"autoload": {
"psr-4": {
diff --git a/docs/containers.rst b/docs/containers.rst
index dc8f2f9a..30566df6 100644
--- a/docs/containers.rst
+++ b/docs/containers.rst
@@ -16,7 +16,7 @@ section, use the following code:
.. code-block:: php
- $section = $phpWord->createSection($sectionSettings);
+ $section = $phpWord->addSection($sectionSettings);
The ``$sectionSettings`` is an optional associative array that sets the
section. Example:
@@ -50,6 +50,7 @@ Below are the available settings for section:
- ``borderBottomColor`` Border bottom color
- ``headerHeight`` Spacing to top of header
- ``footerHeight`` Spacing to bottom of footer
+- ``gutter`` Page gutter spacing
- ``colsNum`` Number of columns
- ``colsSpace`` Spacing between columns
- ``breakType`` Section break type (nextPage, nextColumn, continuous,
@@ -70,10 +71,10 @@ property of the section.
.. code-block:: php
// Method 1
- $section = $phpWord->createSection(array('pageNumberingStart' => 1));
+ $section = $phpWord->addSection(array('pageNumberingStart' => 1));
// Method 2
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->getSettings()->setPageNumberingStart(1);
Multicolumn
@@ -85,22 +86,44 @@ using the ``breakType`` and ``colsNum`` property of the section.
.. code-block:: php
// Method 1
- $section = $phpWord->createSection(array('breakType' => 'continuous', 'colsNum' => 2));
+ $section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2));
// Method 2
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->getSettings()->setBreakType('continuous');
$section->getSettings()->setColsNum(2);
+
+### Line numbering
+
+You can apply line numbering to a section by using the ``lineNumbering``
+property of the section.
+
+.. code-block:: php
+
+ // Method 1
+ $section = $phpWord->addSection(array('lineNumbering' => array()));
+
+ // Method 2
+ $section = $phpWord->addSection();
+ $section->getSettings()->setLineNumbering(array());
+
+Below are the properties of the line numbering style.
+
+- ``start`` Line numbering starting value
+- ``increment`` Line number increments
+- ``distance`` Distance between text and line numbering in twip
+- ``restart`` Line numbering restart setting continuous|newPage|newSection
+
Headers
-------
Each section can have its own header reference. To create a header use
-the ``createHeader`` method:
+the ``addHeader`` method:
.. code-block:: php
- $header = $section->createHeader();
+ $header = $section->addHeader();
Be sure to save the result in a local object. You can use all elements
that are available for the footer. See "Footer" section for detail.
@@ -111,11 +134,11 @@ Footers
-------
Each section can have its own footer reference. To create a footer, use
-the ``createFooter`` method:
+the ``addFooter`` method:
.. code-block:: php
- $footer = $section->createFooter();
+ $footer = $section->addFooter();
Be sure to save the result in a local object to add elements to a
footer. You can add the following elements to footers:
diff --git a/docs/elements.rst b/docs/elements.rst
index d0f78d2e..c86d1074 100644
--- a/docs/elements.rst
+++ b/docs/elements.rst
@@ -3,20 +3,67 @@
Elements
========
+Below are the matrix of element availability in each container. The
+column shows the containers while the rows lists the elements.
+
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| Num | Element | Section | Header | Footer | Cell | Text Run | Footnote |
++=======+=================+===========+==========+==========+=========+============+============+
+| 1 | Text | v | v | v | v | v | v |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 2 | Text Run | v | v | v | v | - | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 3 | Link | v | v | v | v | v | v |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 4 | Title | v | ? | ? | ? | ? | ? |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 5 | Preserve Text | ? | v | v | v\* | ? | ? |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 6 | Text Break | v | v | v | v | v | v |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 7 | Page Break | v | - | - | - | - | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 8 | List | v | v | v | v | - | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 9 | Table | v | v | v | ? | - | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 10 | Image | v | v | v | v | v | v |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 11 | Watermark | - | v | - | - | - | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 12 | Object | v | v | v | v | v | v |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 13 | TOC | v | - | - | - | - | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 14 | Footnote | v | - | - | v\*\* | v\*\* | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 15 | Endnote | v | - | - | v\*\* | v\*\* | - |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 16 | CheckBox | v | v | v | v | ? | ? |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
+
+Legend:
+
+- ``v`` Available
+- ``v*`` Available only when inside header/footer
+- ``v**`` Available only when inside section
+- ``-`` Not available
+- ``?`` Should be available
+
Texts
-----
-Text can be added by using ``addText`` and ``createTextRun`` method.
+Text can be added by using ``addText`` and ``addTextRun`` method.
``addText`` is used for creating simple paragraphs that only contain
-texts with the same style. ``createTextRun`` is used for creating
-complex paragraphs that contain text with different style (some bold,
-other italics, etc) or other elements, e.g. images or links. The
-syntaxes are as follow:
+texts with the same style. ``addTextRun`` is used for creating complex
+paragraphs that contain text with different style (some bold, other
+italics, etc) or other elements, e.g. images or links. The syntaxes are
+as follow:
.. code-block:: php
$section->addText($text, [$fontStyle], [$paragraphStyle]);
- $textrun = $section->createTextRun([$paragraphStyle]);
+ $textrun = $section->addTextRun([$paragraphStyle]);
Text styles
~~~~~~~~~~~
@@ -34,7 +81,7 @@ Inline style examples:
$paragraphStyle = array('align' => 'both');
$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
- $textrun = $section->createTextRun();
+ $textrun = $section->addTextRun();
$textrun->addText('I am bold', array('bold' => true));
$textrun->addText('I am italic', array('italic' => true));
$textrun->addText('I am colored, array('color' => 'AACC00'));
@@ -65,8 +112,12 @@ Available font styles:
- ``subScript`` Subscript, *true* or *false*
- ``underline`` Underline, *dash*, *dotted*, etc.
- ``strikethrough`` Strikethrough, *true* or *false*
+- ``doubleStrikethrough`` Double strikethrough, *true* or *false*
- ``color`` Font color, e.g. *FF0000*
- ``fgColor`` Font highlight color, e.g. *yellow*, *green*, *blue*
+- ``bgColor`` Font background color, e.g. *FF0000*
+- ``smallCaps`` Small caps, *true* or *false*
+- ``allCaps`` All caps, *true* or *false*
Paragraph style
^^^^^^^^^^^^^^^
@@ -152,17 +203,21 @@ method or using the ``pageBreakBefore`` style of paragraph.
:: code-block:: php
- $section->addPageBreak();
+ \\$section->addPageBreak();
Lists
-----
To add a list item use the function ``addListItem``.
+Basic usage:
+
.. code-block:: php
$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
+Parameters:
+
- ``$text`` Text that appears in the document.
- ``$depth`` Depth of list item.
- ``$fontStyle`` See "Font style" section.
@@ -171,6 +226,43 @@ To add a list item use the function ``addListItem``.
PHPWord\_Style\_ListItem.
- ``$paragraphStyle`` See "Paragraph style" section.
+Advanced usage:
+
+You can also create your own numbering style by changing the
+``$listStyle`` parameter with the name of your numbering style.
+
+.. code-block:: php
+
+ $phpWord->addNumberingStyle(
+ 'multilevel',
+ array('type' => 'multilevel', 'levels' => array(
+ array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
+ array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
+ )
+ )
+ );
+ $section->addListItem('List Item I', 0, null, 'multilevel');
+ $section->addListItem('List Item I.a', 1, null, 'multilevel');
+ $section->addListItem('List Item I.b', 1, null, 'multilevel');
+ $section->addListItem('List Item II', 0, null, 'multilevel');
+
+Level styles:
+
+- ``start`` Starting value
+- ``format`` Numbering format
+ bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter
+- ``restart`` Restart numbering level symbol
+- ``suffix`` Content between numbering symbol and paragraph text
+ tab\|space\|nothing
+- ``text`` Numbering level text e.g. %1 for nonbullet or bullet
+ character
+- ``align`` Numbering symbol align left\|center\|right\|both
+- ``left`` See paragraph style
+- ``hanging`` See paragraph style
+- ``tabPos`` See paragraph style
+- ``font`` Font name
+- ``hint`` See font style
+
Tables
------
@@ -201,27 +293,28 @@ Table, row, and cell styles
Table styles:
-- ``$width`` Table width in percent
-- ``$bgColor`` Background color, e.g. '9966CC'
-- ``$border(Top|Right|Bottom|Left)Size`` Border size in twips
-- ``$border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
-- ``$cellMargin(Top|Right|Bottom|Left)`` Cell margin in twips
+- ``width`` Table width in percent
+- ``bgColor`` Background color, e.g. '9966CC'
+- ``border(Top|Right|Bottom|Left)Size`` Border size in twips
+- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
+- ``cellMargin(Top|Right|Bottom|Left)`` Cell margin in twips
Row styles:
- ``tblHeader`` Repeat table row on every new page, *true* or *false*
- ``cantSplit`` Table row cannot break across pages, *true* or *false*
+- ``exactHeight`` Row height is exact or at least
Cell styles:
-- ``$width`` Cell width in twips
-- ``$valign`` Vertical alignment, *top*, *center*, *both*, *bottom*
-- ``$textDirection`` Direction of text
-- ``$bgColor`` Background color, e.g. '9966CC'
-- ``$border(Top|Right|Bottom|Left)Size`` Border size in twips
-- ``$border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
-- ``$gridSpan`` Number of columns spanned
-- ``$vMerge`` *restart* or *continue*
+- ``width`` Cell width in twips
+- ``valign`` Vertical alignment, *top*, *center*, *both*, *bottom*
+- ``textDirection`` Direction of text
+- ``bgColor`` Background color, e.g. '9966CC'
+- ``border(Top|Right|Bottom|Left)Size`` Border size in twips
+- ``border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
+- ``gridSpan`` Number of columns spanned
+- ``vMerge`` *restart* or *continue*
Cell span
~~~~~~~~~
@@ -239,21 +332,21 @@ See ``Sample_09_Tables.php`` for more code sample.
Images
------
-To add an image, use the ``addImage`` method to sections, headers, footers,
-textruns, or table cells.
+To add an image, use the ``addImage`` method to sections, headers,
+footers, textruns, or table cells.
.. code-block:: php
$section->addImage($src, [$style]);
-- `source` String path to a local image or URL of a remote image
-- `styles` Array fo styles for the image. See below.
+- source String path to a local image or URL of a remote image
+- styles Array fo styles for the image. See below.
Examples:
.. code-block:: php
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$section->addImage(
'mars.jpg',
array(
@@ -264,9 +357,9 @@ Examples:
'wrappingStyle' => 'behind'
)
);
- $footer = $section->createFooter();
+ $footer = $section->addFooter();
$footer->addImage('http://example.com/image.php');
- $textrun = $section->createTextRun();
+ $textrun = $section->addTextRun();
$textrun->addImage('http://php.net/logo.jpg');
Image styles
@@ -291,8 +384,8 @@ header reference. After creating a header, you can use the
.. code-block:: php
- $section = $phpWord->createSection();
- $header = $section->createHeader();
+ $section = $phpWord->addSection();
+ $header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
Objects
@@ -314,7 +407,14 @@ Your TOC can only be generated if you have add at least one title (See
.. code-block:: php
- $section->addTOC([$fontStyle], [$tocStyle]);
+ $section->addTOC([$fontStyle], [$tocStyle], [$minDepth], [$maxDepth]);
+
+- ``$fontStyle``: See font style section
+- ``$tocStyle``: See available options below
+- ``$minDepth``: Minimum depth of header to be shown. Default 1
+- ``$maxDepth``: Maximum depth of header to be shown. Default 9
+
+Options for ``$tocStyle``:
- ``tabLeader`` Fill type between the title text and the page number.
Use the defined constants in PHPWord\_Style\_TOC.
@@ -322,26 +422,54 @@ Your TOC can only be generated if you have add at least one title (See
twips.
- ``indent`` The indent factor of the titles in twips.
-Footnotes
----------
+Footnotes & endnotes
+--------------------
-You can create footnotes in texts or textruns, but it's recommended to
-use textrun to have better layout.
+You can create footnotes with ``addFootnote`` and endnotes with
+``addEndnote`` in texts or textruns, but it's recommended to use textrun
+to have better layout. You can use ``addText``, ``addLink``,
+``addTextBreak``, ``addImage``, ``addObject`` on footnotes and endnotes.
On textrun:
.. code-block:: php
- $textrun = $section->createTextRun();
+ $textrun = $section->addTextRun();
$textrun->addText('Lead text.');
- $footnote = $textrun->createFootnote();
- $footnote->addText('Footnote text.');
+ $footnote = $textrun->addFootnote();
+ $footnote->addText('Footnote text can have ');
+ $footnote->addLink('http://test.com', 'links');
+ $footnote->addText('.');
+ $footnote->addTextBreak();
+ $footnote->addText('And text break.');
$textrun->addText('Trailing text.');
+ $endnote = $textrun->addEndnote();
+ $endnote->addText('Endnote put at the end');
On text:
.. code-block:: php
$section->addText('Lead text.');
- $footnote = $section->createFootnote();
+ $footnote = $section->addFootnote();
$footnote->addText('Footnote text.');
+
+The footnote reference number will be displayed with decimal number
+starting from 1. This number use ``FooterReference`` style which you can
+redefine by ``addFontStyle`` method. Default value for this style is
+``array('superScript' => true)``;
+
+Checkboxes
+----------
+
+Checkbox elements can be added to sections or table cells by using
+``addCheckBox``.
+
+.. code-block:: php
+
+ $section->addCheckBox($name, $text, [$fontStyle], [$paragraphStyle])
+
+- ``$name`` Name of the check box.
+- ``$text`` Text following the check box
+- ``$fontStyle`` See "Font style" section.
+- ``$paragraphStyle`` See "Paragraph style" section.
diff --git a/docs/general.rst b/docs/general.rst
index 9b25551a..f08e29ba 100644
--- a/docs/general.rst
+++ b/docs/general.rst
@@ -7,18 +7,19 @@ Basic example
-------------
The following is a basic example of the PHPWord library. More examples
-are provided in the `samples folder `__.
+are provided in the `samples
+folder `__.
.. code-block:: php
require_once 'src/PhpWord/Autoloader.php';
- PhpOffice\PhpWord\Autoloader::register();
+ \PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
@@ -52,6 +53,43 @@ are provided in the `samples folder save('helloWorld.rtf');
+Settings
+--------
+
+The ``PhpOffice\PhpWord\Settings`` class provides some options that will
+affect the behavior of PHPWord. Below are the options.
+
+XML Writer compatibility
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+This option sets
+`XMLWriter::setIndent `__
+and
+`XMLWriter::setIndentString `__.
+The default value of this option is ``true`` (compatible), which is
+`required for
+OpenOffice `__ to
+render OOXML document correctly. You can set this option to ``false``
+during development to make the resulting XML file easier to read.
+
+.. code-block:: php
+
+ \PhpOffice\PhpWord\Settings::setCompatibility(false);
+
+Zip class
+~~~~~~~~~
+
+By default, PHPWord uses PHP
+`ZipArchive `__ to read or write
+ZIP compressed archive and the files inside them. If you can't have
+ZipArchive installed on your server, you can use pure PHP library
+alternative, `PCLZip `__, which
+included with PHPWord.
+
+.. code-block:: php
+
+ \PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
+
Default font
------------
@@ -71,7 +109,7 @@ name. Use the following functions:
.. code-block:: php
- $properties = $phpWord->getProperties();
+ $properties = $phpWord->getDocumentProperties();
$properties->setCreator('My name');
$properties->setCompany('My factory');
$properties->setTitle('My title');
@@ -99,9 +137,10 @@ points to twips.
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
);
- $section = $phpWord->createSection();
+ $section = $phpWord->addSection();
$sectionStyle = $section->getSettings();
// half inch left margin
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));
+
diff --git a/docs/index.rst b/docs/index.rst
index 700694a5..fd3a3fa9 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -23,6 +23,7 @@ Format (RTF).
containers
elements
templates
+ writersreaders
recipes
faq
credits
diff --git a/docs/intro.rst b/docs/intro.rst
index a30dc553..3e74519e 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -16,9 +16,9 @@ No Windows operating system is needed for usage because the resulting
DOCX, ODT, or RTF files can be opened by all major `word processing
softwares `__.
-PHPWord is an open source project licensed under LGPL.
-PHPWord is `unit tested `__ to
-make sure that the released versions are stable.
+PHPWord is an open source project licensed under LGPL. PHPWord is `unit
+tested `__ to make sure that
+the released versions are stable.
**Want to contribute?** `Fork
us `__ or
@@ -48,6 +48,7 @@ Features
rowspan, colspan)
- Insert list items as bulleted, numbered, or multilevel
- Insert hyperlinks
+- Insert footnotes and endnotes
- Create document from templates
- Use XSL 1.0 style sheets to transform main document part of OOXML
template
@@ -61,122 +62,121 @@ Below are the supported features for each file formats.
Writers
~~~~~~~
-+-------------------------------------------------+--------+-------+-------+
-| Features | DOCX | ODT | RTF |
-+=========================+=======================+========+=======+=======+
-| **Document Properties** | Standard | | | |
-+ +-----------------------+--------+-------+-------+
-| | Extended | | | |
-+ +-----------------------+--------+-------+-------+
-| | UserDefined | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Element Type** | Text | ✓ | ✓ | ✓ |
-+ +-----------------------+--------+-------+-------+
-| | Text Run | ✓ | ✓ | ✓ |
-+ +-----------------------+--------+-------+-------+
-| | Title | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Link | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Preserve Text | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Text Break | ✓ | ✓ | ✓ |
-+ +-----------------------+--------+-------+-------+
-| | Page Break | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | List | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Table | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Image | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | MemoryImage | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Object | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Watermark | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Table of Contents | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Header | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Footer | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Footnote | ✓ | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Graphs** | 2D basic graphs | | | |
-+ +-----------------------+--------+-------+-------+
-| | 2D advanced graphs | | | |
-+ +-----------------------+--------+-------+-------+
-| | 3D graphs | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Math** | OMML support | | | |
-+ +-----------------------+--------+-------+-------+
-| | MathML support | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Bonus** | Encryption | | | |
-+ +-----------------------+--------+-------+-------+
-| | Protection | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| Features | | DOCX | ODT | RTF | HTML | PDF |
++===========================+======================+========+=======+=======+========+=======+
+| **Document Properties** | Standard | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Extended | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | UserDefined | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Title | ✓ | | | ✓ | ✓ |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Link | ✓ | ✓ | | ✓ | ✓ |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Preserve Text | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Page Break | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | List | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Table | ✓ | ✓ | | ✓ | ✓ |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Image | ✓ | ✓ | | ✓ | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Object | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Watermark | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Table of Contents | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Header | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Footer | ✓ | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Footnote | ✓ | | | ✓ | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Endnote | ✓ | | | ✓ | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| **Graphs** | 2D basic graphs | | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | 2D advanced graphs | | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | 3D graphs | | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| **Math** | OMML support | | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | MathML support | | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| **Bonus** | Encryption | | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
+| | Protection | | | | | |
++---------------------------+----------------------+--------+-------+-------+--------+-------+
Readers
~~~~~~~
-+-------------------------------------------------+--------+-------+-------+
-| Features | DOCX | ODT | RTF |
-+=========================+=======================+========+=======+=======+
-| **Document Properties** | Standard | | | |
-+ +-----------------------+--------+-------+-------+
-| | Extended | | | |
-+ +-----------------------+--------+-------+-------+
-| | UserDefined | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Element Type** | Text | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Text Run | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Title | | | |
-+ +-----------------------+--------+-------+-------+
-| | Link | | | |
-+ +-----------------------+--------+-------+-------+
-| | Preserve Text | | | |
-+ +-----------------------+--------+-------+-------+
-| | Text Break | ✓ | | |
-+ +-----------------------+--------+-------+-------+
-| | Page Break | | | |
-+ +-----------------------+--------+-------+-------+
-| | List | | | |
-+ +-----------------------+--------+-------+-------+
-| | Table | | | |
-+ +-----------------------+--------+-------+-------+
-| | Image | | | |
-+ +-----------------------+--------+-------+-------+
-| | MemoryImage | | | |
-+ +-----------------------+--------+-------+-------+
-| | Object | | | |
-+ +-----------------------+--------+-------+-------+
-| | Watermark | | | |
-+ +-----------------------+--------+-------+-------+
-| | Table of Contents | | | |
-+ +-----------------------+--------+-------+-------+
-| | Header | | | |
-+ +-----------------------+--------+-------+-------+
-| | Footer | | | |
-+ +-----------------------+--------+-------+-------+
-| | Footnote | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Graphs** | 2D basic graphs | | | |
-+ +-----------------------+--------+-------+-------+
-| | 2D advanced graphs | | | |
-+ +-----------------------+--------+-------+-------+
-| | 3D graphs | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Math** | OMML support | | | |
-+ +-----------------------+--------+-------+-------+
-| | MathML support | | | |
-+-------------------------+-----------------------+--------+-------+-------+
-| **Bonus** | Encryption | | | |
-+ +-----------------------+--------+-------+-------+
-| | Protection | | | |
-+-------------------------+-----------------------+--------+-------+-------+
++---------------------------+----------------------+--------+-------+-------+
+| Features | | DOCX | ODT | RTF |
++===========================+======================+========+=======+=======+
+| **Document Properties** | Standard | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Extended | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | UserDefined | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| **Element Type** | Text | ✓ | ✓ | |
++---------------------------+----------------------+--------+-------+-------+
+| | Text Run | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Title | ✓ | ✓ | |
++---------------------------+----------------------+--------+-------+-------+
+| | Link | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Preserve Text | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Text Break | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Page Break | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | List | ✓ | ✓ | |
++---------------------------+----------------------+--------+-------+-------+
+| | Table | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Image | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Object | | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Watermark | | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Table of Contents | | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Header | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Footer | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Footnote | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Endnote | ✓ | | |
++---------------------------+----------------------+--------+-------+-------+
+| **Graphs** | 2D basic graphs | | | |
++---------------------------+----------------------+--------+-------+-------+
+| | 2D advanced graphs | | | |
++---------------------------+----------------------+--------+-------+-------+
+| | 3D graphs | | | |
++---------------------------+----------------------+--------+-------+-------+
+| **Math** | OMML support | | | |
++---------------------------+----------------------+--------+-------+-------+
+| | MathML support | | | |
++---------------------------+----------------------+--------+-------+-------+
+| **Bonus** | Encryption | | | |
++---------------------------+----------------------+--------+-------+-------+
+| | Protection | | | |
++---------------------------+----------------------+--------+-------+-------+
diff --git a/docs/setup.rst b/docs/setup.rst
index c773756f..e5d61b4e 100644
--- a/docs/setup.rst
+++ b/docs/setup.rst
@@ -1,6 +1,6 @@
.. _setup:
-Installing/Configuring
+Installing/configuring
======================
Requirements
@@ -53,7 +53,7 @@ invoke ``Autoloader::register``.
.. code-block:: php
require_once '/path/to/src/PhpWord/Autoloader.php';
- PhpOffice\PhpWord\Autoloader::register();
+ \PhpOffice\PhpWord\Autoloader::register();
Using samples
-------------
diff --git a/docs/src/documentation.md b/docs/src/documentation.md
new file mode 100644
index 00000000..bcf38a04
--- /dev/null
+++ b/docs/src/documentation.md
@@ -0,0 +1,950 @@
+
+# Contents
+
+- [Introduction](#introduction)
+ - [Features](#features)
+ - [File formats](#file-formats)
+- [Installing/configuring](#installing-configuring)
+ - [Requirements](#requirements)
+ - [Installation](#installation)
+ - [Using samples](#using-samples)
+- [General usage](#general-usage)
+ - [Basic example](#basic-example)
+ - [Settings](#settings)
+ - [Default font](#default-font)
+ - [Document properties](#document-properties)
+ - [Measurement units](#measurement-units)
+- [Containers](#containers)
+ - [Sections](#sections)
+ - [Headers](#headers)
+ - [Footers](#footers)
+ - [Other containers](#other-containers)
+- [Elements](#elements)
+ - [Texts](#texts)
+ - [Breaks](#breaks)
+ - [Lists](#lists)
+ - [Tables](#tables)
+ - [Images](#images)
+ - [Objects](#objects)
+ - [Table of contents](#table-of-contents)
+ - [Footnotes & endnotes](#footnotes-endnotes)
+ - [Checkboxes](#checkboxes)
+- [Templates](#templates)
+- [Writers & readers](#writers-readers)
+ - [OOXML](#ooxml)
+ - [OpenDocument](#opendocument)
+ - [RTF](#rtf)
+ - [HTML](#html)
+ - [PDF](#pdf)
+- [Frequently asked questions](#frequently-asked-questions)
+- [References](#references)
+
+# Introduction
+
+PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF).
+
+No Windows operating system is needed for usage because the resulting DOCX, ODT, or RTF files can be opened by all major [word processing softwares](http://en.wikipedia.org/wiki/List_of_word_processors).
+
+PHPWord is an open source project licensed under LGPL. PHPWord is [unit tested](https://travis-ci.org/PHPOffice/PHPWord) to make sure that the released versions are stable.
+
+**Want to contribute?** [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us.
+
+## Features
+
+- Set document properties, e.g. title, subject, and creator.
+- Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
+- Create header and footer for each sections
+- Set default font type, font size, and paragraph style
+- Use UTF-8 and East Asia fonts/characters
+- Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text
+- Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
+- Insert titles (headers) and table of contents
+- Insert text breaks and page breaks
+- Insert and format images, either local, remote, or as page watermarks
+- Insert binary OLE Objects such as Excel or Visio
+- Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan)
+- Insert list items as bulleted, numbered, or multilevel
+- Insert hyperlinks
+- Insert footnotes and endnotes
+- Create document from templates
+- Use XSL 1.0 style sheets to transform main document part of OOXML template
+- ... and many more features on progress
+
+## File formats
+
+Below are the supported features for each file formats.
+
+### Writers
+
+| Features | | DOCX | ODT | RTF | HTML | PDF |
+|-------------------------|--------------------|------|-----|-----|------|-----|
+| **Document Properties** | Standard | ✓ | | | | |
+| | Extended | ✓ | | | | |
+| | UserDefined | ✓ | | | | |
+| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
+| | Text Run | ✓ | ✓ | ✓ | ✓ | ✓ |
+| | Title | ✓ | | | ✓ | ✓ |
+| | Link | ✓ | ✓ | | ✓ | ✓ |
+| | Preserve Text | ✓ | | | | |
+| | Text Break | ✓ | ✓ | ✓ | ✓ | ✓ |
+| | Page Break | ✓ | | | | |
+| | List | ✓ | | | | |
+| | Table | ✓ | ✓ | | ✓ | ✓ |
+| | Image | ✓ | ✓ | | ✓ | |
+| | Object | ✓ | | | | |
+| | Watermark | ✓ | | | | |
+| | Table of Contents | ✓ | | | | |
+| | Header | ✓ | | | | |
+| | Footer | ✓ | | | | |
+| | Footnote | ✓ | | | ✓ | |
+| | Endnote | ✓ | | | ✓ | |
+| **Graphs** | 2D basic graphs | | | | | |
+| | 2D advanced graphs | | | | | |
+| | 3D graphs | | | | | |
+| **Math** | OMML support | | | | | |
+| | MathML support | | | | | |
+| **Bonus** | Encryption | | | | | |
+| | Protection | | | | | |
+
+### Readers
+
+| Features | | DOCX | ODT | RTF |
+|-------------------------|--------------------|------|-----|-----|
+| **Document Properties** | Standard | ✓ | | |
+| | Extended | ✓ | | |
+| | UserDefined | ✓ | | |
+| **Element Type** | Text | ✓ | ✓ | |
+| | Text Run | ✓ | | |
+| | Title | ✓ | ✓ | |
+| | Link | ✓ | | |
+| | Preserve Text | ✓ | | |
+| | Text Break | ✓ | | |
+| | Page Break | ✓ | | |
+| | List | ✓ | ✓ | |
+| | Table | ✓ | | |
+| | Image | ✓ | | |
+| | Object | | | |
+| | Watermark | | | |
+| | Table of Contents | | | |
+| | Header | ✓ | | |
+| | Footer | ✓ | | |
+| | Footnote | ✓ | | |
+| | Endnote | ✓ | | |
+| **Graphs** | 2D basic graphs | | | |
+| | 2D advanced graphs | | | |
+| | 3D graphs | | | |
+| **Math** | OMML support | | | |
+| | MathML support | | | |
+| **Bonus** | Encryption | | | |
+| | Protection | | | |
+
+# Installing/configuring
+
+## Requirements
+
+Mandatory:
+
+- PHP 5.3+
+- PHP [Zip](http://php.net/manual/en/book.zip.php) extension
+- PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension
+
+Optional PHP extensions:
+
+- [GD](http://php.net/manual/en/book.image.php)
+- [XMLWriter](http://php.net/manual/en/book.xmlwriter.php)
+- [XSL](http://php.net/manual/en/book.xsl.php)
+
+## Installation
+
+There are two ways to install PHPWord, i.e. via [Composer](http://getcomposer.org/) or manually by downloading the library.
+
+### Using Composer
+
+To install via Composer, add the following lines to your `composer.json`:
+
+```json
+{
+ "require": {
+ "phpoffice/phpword": "dev-master"
+ }
+}
+```
+
+### Manual install
+
+To install manually, [download PHPWord package from github](https://github.com/PHPOffice/PHPWord/archive/master.zip). Extract the package and put the contents to your machine. To use the library, include `src/PhpWord/Autoloader.php` in your script and invoke `Autoloader::register`.
+
+```php
+require_once '/path/to/src/PhpWord/Autoloader.php';
+\PhpOffice\PhpWord\Autoloader::register();
+```
+
+## Using samples
+
+After installation, you can browse and use the samples that we've provided, either by command line or using browser. If you can access your PHPWord library folder using browser, point your browser to the `samples` folder, e.g. `http://localhost/PhpWord/samples/`.
+
+# General usage
+
+## Basic example
+
+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/).
+
+```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.
+// To create a basic section:
+$section = $phpWord->addSection();
+
+// After creating a section, you can append elements:
+$section->addText('Hello world!');
+
+// You can directly style your text by giving the addText function an array:
+$section->addText('Hello world! I am formatted.',
+ array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
+
+// If you often need the same style again you can create a user defined style
+// to the word document and give the addText function the name of the style:
+$phpWord->addFontStyle('myOwnStyle',
+ array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
+$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);
+$myTextElement = $section->addText('Hello World!');
+$myTextElement->setFontStyle($fontStyle);
+
+// Finally, write the document:
+$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
+$objWriter->save('helloWorld.docx');
+
+$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
+$objWriter->save('helloWorld.odt');
+
+$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
+$objWriter->save('helloWorld.rtf');
+```
+
+## Settings
+
+The `PhpOffice\PhpWord\Settings` class provides some options that will affect the behavior of PHPWord. Below are the options.
+
+### XML Writer compatibility
+
+This option sets [XMLWriter::setIndent](http://www.php.net/manual/en/function.xmlwriter-set-indent.php) and [XMLWriter::setIndentString](http://www.php.net/manual/en/function.xmlwriter-set-indent-string.php). The default value of this option is `true` (compatible), which is [required for OpenOffice](https://github.com/PHPOffice/PHPWord/issues/103) to render OOXML document correctly. You can set this option to `false` during development to make the resulting XML file easier to read.
+
+```php
+\PhpOffice\PhpWord\Settings::setCompatibility(false);
+```
+
+### Zip class
+
+By default, PHPWord uses PHP [ZipArchive](http://php.net/manual/en/book.zip.php) to read or write ZIP compressed archive and the files inside them. If you can't have ZipArchive installed on your server, you can use pure PHP library alternative, [PCLZip](http://www.phpconcept.net/pclzip/), which included with PHPWord.
+
+```php
+\PhpOffice\PhpWord\Settings::setZipClass(\PhpOffice\PhpWord\Settings::PCLZIP);
+```
+
+## Default font
+
+By default, every text appears in Arial 10 point. You can alter the default font by using the following two functions:
+
+```php
+$phpWord->setDefaultFontName('Times New Roman');
+$phpWord->setDefaultFontSize(12);
+```
+
+## Document properties
+
+You can set the document properties such as title, creator, and company name. Use the following functions:
+
+```php
+$properties = $phpWord->getDocumentProperties();
+$properties->setCreator('My name');
+$properties->setCompany('My factory');
+$properties->setTitle('My title');
+$properties->setDescription('My description');
+$properties->setCategory('My category');
+$properties->setLastModifiedBy('My name');
+$properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
+$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
+$properties->setSubject('My subject');
+$properties->setKeywords('my, key, word');
+```
+
+## Measurement units
+
+The base length unit in Open Office XML is twip. Twip means "TWentieth of an Inch Point", i.e. 1 twip = 1/1440 inch.
+
+You can use PHPWord helper functions to convert inches, centimeters, or points to twips.
+
+```php
+// Paragraph with 6 points space after
+$phpWord->addParagraphStyle('My Style', array(
+ 'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
+);
+
+$section = $phpWord->addSection();
+$sectionStyle = $section->getSettings();
+// half inch left margin
+$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
+// 2 cm right margin
+$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));
+```
+
+# Containers
+
+Containers are objects where you can put elements (texts, lists, tables, etc). There are 3 main containers, i.e. sections, headers, and footers. There are 3 elements that can also act as containers, i.e. textruns, table cells, and footnotes.
+
+## Sections
+
+Every visible element in word is placed inside of a section. To create a section, use the following code:
+
+```php
+$section = $phpWord->addSection($sectionSettings);
+```
+
+The `$sectionSettings` is an optional associative array that sets the section. Example:
+
+```php
+$sectionSettings = array(
+ 'orientation' => 'landscape',
+ 'marginTop' => 600,
+ 'colsNum' => 2,
+);
+```
+
+### Section settings
+
+Below are the available settings for section:
+
+- `orientation` Page orientation, i.e. 'portrait' (default) or 'landscape'
+- `marginTop` Page margin top in twips
+- `marginLeft` Page margin left in twips
+- `marginRight` Page margin right in twips
+- `marginBottom` Page margin bottom in twips
+- `borderTopSize` Border top size in twips
+- `borderTopColor` Border top color
+- `borderLeftSize` Border left size in twips
+- `borderLeftColor` Border left color
+- `borderRightSize` Border right size in twips
+- `borderRightColor` Border right color
+- `borderBottomSize` Border bottom size in twips
+- `borderBottomColor` Border bottom color
+- `headerHeight` Spacing to top of header
+- `footerHeight` Spacing to bottom of footer
+- `gutter` Page gutter spacing
+- `colsNum` Number of columns
+- `colsSpace` Spacing between columns
+- `breakType` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage)
+
+The following two settings are automatically set by the use of the `orientation` setting. You can alter them but that's not recommended.
+
+- `pageSizeW` Page width in twips
+- `pageSizeH` Page height in twips
+
+### Page number
+
+You can change a section page number by using the `pageNumberingStart` property of the section.
+
+```php
+// Method 1
+$section = $phpWord->addSection(array('pageNumberingStart' => 1));
+
+// Method 2
+$section = $phpWord->addSection();
+$section->getSettings()->setPageNumberingStart(1);
+```
+
+### Multicolumn
+
+You can change a section layout to multicolumn (like in a newspaper) by using the `breakType` and `colsNum` property of the section.
+
+```php
+// Method 1
+$section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2));
+
+// Method 2
+$section = $phpWord->addSection();
+$section->getSettings()->setBreakType('continuous');
+$section->getSettings()->setColsNum(2);
+```
+
+### Line numbering
+
+You can apply line numbering to a section by using the `lineNumbering` property of the section.
+
+```php
+// Method 1
+$section = $phpWord->addSection(array('lineNumbering' => array()));
+
+// Method 2
+$section = $phpWord->addSection();
+$section->getSettings()->setLineNumbering(array());
+```
+
+Below are the properties of the line numbering style.
+
+- `start` Line numbering starting value
+- `increment` Line number increments
+- `distance` Distance between text and line numbering in twip
+- `restart` Line numbering restart setting continuous|newPage|newSection
+
+## Headers
+
+Each section can have its own header reference. To create a header use the `addHeader` method:
+
+```php
+$header = $section->addHeader();
+```
+
+Be sure to save the result in a local object. You can use all elements that are available for the footer. See "Footer" section for detail. Additionally, only inside of the header reference you can add watermarks or background pictures. See "Watermarks" section.
+
+## Footers
+
+Each section can have its own footer reference. To create a footer, use the `addFooter` method:
+
+```php
+$footer = $section->addFooter();
+```
+
+Be sure to save the result in a local object to add elements to a footer. You can add the following elements to footers:
+
+- Texts `addText` and `createTextrun`
+- Text breaks
+- Images
+- Tables
+- Preserve text
+
+See the "Elements" section for the detail of each elements.
+
+## Other containers
+
+Textruns, table cells, and footnotes are elements that can also act as containers. See the corresponding "Elements" section for the detail of each elements.
+
+# Elements
+
+Below are the matrix of element availability in each container. The column shows the containers while the rows lists the elements.
+
+| Num | Element | Section | Header | Footer | Cell | Text Run | Footnote |
+|-----|---------------|---------|--------|--------|------|----------|----------|
+| 1 | Text | v | v | v | v | v | v |
+| 2 | Text Run | v | v | v | v | - | - |
+| 3 | Link | v | v | v | v | v | v |
+| 4 | Title | v | ? | ? | ? | ? | ? |
+| 5 | Preserve Text | ? | v | v | v* | ? | ? |
+| 6 | Text Break | v | v | v | v | v | v |
+| 7 | Page Break | v | - | - | - | - | - |
+| 8 | List | v | v | v | v | - | - |
+| 9 | Table | v | v | v | ? | - | - |
+| 10 | Image | v | v | v | v | v | v |
+| 11 | Watermark | - | v | - | - | - | - |
+| 12 | Object | v | v | v | v | v | v |
+| 13 | TOC | v | - | - | - | - | - |
+| 14 | Footnote | v | - | - | v** | v** | - |
+| 15 | Endnote | v | - | - | v** | v** | - |
+| 16 | CheckBox | v | v | v | v | ? | ? |
+
+Legend:
+
+- `v` Available
+- `v*` Available only when inside header/footer
+- `v**` Available only when inside section
+- `-` Not available
+- `?` Should be available
+
+## Texts
+
+Text can be added by using `addText` and `addTextRun` method. `addText` is used for creating simple paragraphs that only contain texts with the same style. `addTextRun` is used for creating complex paragraphs that contain text with different style (some bold, other italics, etc) or other elements, e.g. images or links. The syntaxes are as follow:
+
+```php
+$section->addText($text, [$fontStyle], [$paragraphStyle]);
+$textrun = $section->addTextRun([$paragraphStyle]);
+```
+
+### Text styles
+
+You can use the `$fontStyle` and `$paragraphStyle` variable to define text formatting. There are 2 options to style the inserted text elements, i.e. inline style by using array or defined style by adding style definition.
+
+Inline style examples:
+
+```php
+$fontStyle = array('name' => 'Times New Roman', 'size' => 9);
+$paragraphStyle = array('align' => 'both');
+$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
+
+$textrun = $section->addTextRun();
+$textrun->addText('I am bold', array('bold' => true));
+$textrun->addText('I am italic', array('italic' => true));
+$textrun->addText('I am colored, array('color' => 'AACC00'));
+```
+
+Defined style examples:
+
+```php
+$fontStyle = array('color' => '006699', 'size' => 18, 'bold' => true);
+$phpWord->addFontStyle('fStyle', $fontStyle);
+$text = $section->addText('Hello world!', 'fStyle');
+
+$paragraphStyle = array('align' => 'center');
+$phpWord->addParagraphStyle('pStyle', $paragraphStyle);
+$text = $section->addText('Hello world!', 'pStyle');
+```
+
+#### Font style
+
+Available font styles:
+
+- `name` Font name, e.g. *Arial*
+- `size` Font size, e.g. *20*, *22*,
+- `hint` Font content type, *default*, *eastAsia*, or *cs*
+- `bold` Bold, *true* or *false*
+- `italic` Italic, *true* or *false*
+- `superScript` Superscript, *true* or *false*
+- `subScript` Subscript, *true* or *false*
+- `underline` Underline, *dash*, *dotted*, etc.
+- `strikethrough` Strikethrough, *true* or *false*
+- `doubleStrikethrough` Double strikethrough, *true* or *false*
+- `color` Font color, e.g. *FF0000*
+- `fgColor` Font highlight color, e.g. *yellow*, *green*, *blue*
+- `bgColor` Font background color, e.g. *FF0000*
+- `smallCaps` Small caps, *true* or *false*
+- `allCaps` All caps, *true* or *false*
+
+#### Paragraph style
+
+Available paragraph styles:
+
+- `align` Paragraph alignment, *left*, *right* or *center*
+- `spaceBefore` Space before paragraph
+- `spaceAfter` Space after paragraph
+- `indent` Indent by how much
+- `hanging` Hanging by how much
+- `basedOn` Parent style
+- `next` Style for next paragraph
+- `widowControl` Allow first/last line to display on a separate page, *true* or *false*
+- `keepNext` Keep paragraph with next paragraph, *true* or *false*
+- `keepLines` Keep all lines on one page, *true* or *false*
+- `pageBreakBefore` Start paragraph on next page, *true* or *false*
+- `lineHeight` text line height, e.g. *1.0*, *1.5*, ect...
+- `tabs` Set of custom tab stops
+
+### Titles
+
+If you want to structure your document or build table of contents, you need titles or headings. To add a title to the document, use the `addTitleStyle` and `addTitle` method.
+
+```php
+$phpWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]);
+$section->addTitle($text, [$depth]);
+```
+
+Its necessary to add a title style to your document because otherwise the title won't be detected as a real title.
+
+### Links
+
+You can add Hyperlinks to the document by using the function addLink:
+
+```php
+$section->addLink($linkSrc, [$linkName], [$fontStyle], [$paragraphStyle]);
+```
+
+- `$linkSrc` The URL of the link.
+- `$linkName` Placeholder of the URL that appears in the document.
+- `$fontStyle` See "Font style" section.
+- `$paragraphStyle` See "Paragraph style" section.
+
+### Preserve texts
+
+The `addPreserveText` method is used to add a page number or page count to headers or footers.
+
+```php
+$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.');
+```
+
+## Breaks
+
+### Text breaks
+
+Text breaks are empty new lines. To add text breaks, use the following syntax. All paramaters are optional.
+
+```php
+$section->addTextBreak([$breakCount], [$fontStyle], [$paragraphStyle]);
+```
+
+- `$breakCount` How many lines
+- `$fontStyle` See "Font style" section.
+- `$paragraphStyle` See "Paragraph style" section.
+
+### Page breaks
+
+There are two ways to insert a page breaks, using the `addPageBreak` method or using the `pageBreakBefore` style of paragraph.
+
+:: code-block:: php
+
+> \$section-\>addPageBreak();
+
+## Lists
+
+To add a list item use the function `addListItem`.
+
+Basic usage:
+
+```php
+$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
+```
+
+Parameters:
+
+- `$text` Text that appears in the document.
+- `$depth` Depth of list item.
+- `$fontStyle` See "Font style" section.
+- `$listStyle` List style of the current element TYPE\_NUMBER, TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in PHPWord\_Style\_ListItem.
+- `$paragraphStyle` See "Paragraph style" section.
+
+Advanced usage:
+
+You can also create your own numbering style by changing the `$listStyle` parameter with the name of your numbering style.
+
+```php
+$phpWord->addNumberingStyle(
+ 'multilevel',
+ array('type' => 'multilevel', 'levels' => array(
+ array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
+ array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
+ )
+ )
+);
+$section->addListItem('List Item I', 0, null, 'multilevel');
+$section->addListItem('List Item I.a', 1, null, 'multilevel');
+$section->addListItem('List Item I.b', 1, null, 'multilevel');
+$section->addListItem('List Item II', 0, null, 'multilevel');
+```
+
+Level styles:
+
+- `start` Starting value
+- `format` Numbering format bullet|decimal|upperRoman|lowerRoman|upperLetter|lowerLetter
+- `restart` Restart numbering level symbol
+- `suffix` Content between numbering symbol and paragraph text tab|space|nothing
+- `text` Numbering level text e.g. %1 for nonbullet or bullet character
+- `align` Numbering symbol align left|center|right|both
+- `left` See paragraph style
+- `hanging` See paragraph style
+- `tabPos` See paragraph style
+- `font` Font name
+- `hint` See font style
+
+## Tables
+
+To add tables, rows, and cells, use the `addTable`, `addRow`, and `addCell` methods:
+
+```php
+$table = $section->addTable([$tableStyle]);
+$table->addRow([$height], [$rowStyle]);
+$cell = $table->addCell($width, [$cellStyle]);
+```
+
+Table style can be defined with `addTableStyle`:
+
+```php
+$tableStyle = array(
+ 'borderColor' => '006699',
+ 'borderSize' => 6,
+ 'cellMargin' => 50
+);
+$firstRowStyle = array('bgColor' => '66BBFF');
+$phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
+$table = $section->addTable('myTable');
+```
+
+### Table, row, and cell styles
+
+Table styles:
+
+- `width` Table width in percent
+- `bgColor` Background color, e.g. '9966CC'
+- `border(Top|Right|Bottom|Left)Size` Border size in twips
+- `border(Top|Right|Bottom|Left)Color` Border color, e.g. '9966CC'
+- `cellMargin(Top|Right|Bottom|Left)` Cell margin in twips
+
+Row styles:
+
+- `tblHeader` Repeat table row on every new page, *true* or *false*
+- `cantSplit` Table row cannot break across pages, *true* or *false*
+- `exactHeight` Row height is exact or at least
+
+Cell styles:
+
+- `width` Cell width in twips
+- `valign` Vertical alignment, *top*, *center*, *both*, *bottom*
+- `textDirection` Direction of text
+- `bgColor` Background color, e.g. '9966CC'
+- `border(Top|Right|Bottom|Left)Size` Border size in twips
+- `border(Top|Right|Bottom|Left)Color` Border color, e.g. '9966CC'
+- `gridSpan` Number of columns spanned
+- `vMerge` *restart* or *continue*
+
+### Cell span
+
+You can span a cell on multiple columns by using `gridSpan` or multiple rows by using `vMerge`.
+
+```php
+$cell = $table->addCell(200);
+$cell->getStyle()->setGridSpan(5);
+```
+
+See `Sample_09_Tables.php` for more code sample.
+
+## Images
+
+To add an image, use the `addImage` method to sections, headers, footers, textruns, or table cells.
+
+```php
+$section->addImage($src, [$style]);
+```
+
+- source String path to a local image or URL of a remote image
+- styles Array fo styles for the image. See below.
+
+Examples:
+
+```php
+$section = $phpWord->addSection();
+$section->addImage(
+ 'mars.jpg',
+ array(
+ 'width' => 100,
+ 'height' => 100,
+ 'marginTop' => -1,
+ 'marginLeft' => -1,
+ 'wrappingStyle' => 'behind'
+ )
+);
+$footer = $section->addFooter();
+$footer->addImage('http://example.com/image.php');
+$textrun = $section->addTextRun();
+$textrun->addImage('http://php.net/logo.jpg');
+```
+
+### Image styles
+
+Available image styles:
+
+- `width` Width in pixels
+- `height` Height in pixels
+- `align` Image alignment, *left*, *right*, or *center*
+- `marginTop` Top margin in inches, can be negative
+- `marginLeft` Left margin in inches, can be negative
+- `wrappingStyle` Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*
+
+### Watermarks
+
+To add a watermark (or page background image), your section needs a header reference. After creating a header, you can use the `addWatermark` method to add a watermark.
+
+```php
+$section = $phpWord->addSection();
+$header = $section->addHeader();
+$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
+```
+
+## Objects
+
+You can add OLE embeddings, such as Excel spreadsheets or PowerPoint presentations to the document by using `addObject` method.
+
+```php
+$section->addObject($src, [$style]);
+```
+
+## Table of contents
+
+To add a table of contents (TOC), you can use the `addTOC` method. Your TOC can only be generated if you have add at least one title (See "Titles").
+
+```php
+$section->addTOC([$fontStyle], [$tocStyle], [$minDepth], [$maxDepth]);
+```
+
+- `$fontStyle`: See font style section
+- `$tocStyle`: See available options below
+- `$minDepth`: Minimum depth of header to be shown. Default 1
+- `$maxDepth`: Maximum depth of header to be shown. Default 9
+
+Options for `$tocStyle`:
+
+- `tabLeader` Fill type between the title text and the page number. Use the defined constants in PHPWord\_Style\_TOC.
+- `tabPos` The position of the tab where the page number appears in twips.
+- `indent` The indent factor of the titles in twips.
+
+## Footnotes & endnotes
+
+You can create footnotes with `addFootnote` and endnotes with `addEndnote` in texts or textruns, but it's recommended to use textrun to have better layout. You can use `addText`, `addLink`, `addTextBreak`, `addImage`, `addObject` on footnotes and endnotes.
+
+On textrun:
+
+```php
+$textrun = $section->addTextRun();
+$textrun->addText('Lead text.');
+$footnote = $textrun->addFootnote();
+$footnote->addText('Footnote text can have ');
+$footnote->addLink('http://test.com', 'links');
+$footnote->addText('.');
+$footnote->addTextBreak();
+$footnote->addText('And text break.');
+$textrun->addText('Trailing text.');
+$endnote = $textrun->addEndnote();
+$endnote->addText('Endnote put at the end');
+```
+
+On text:
+
+```php
+$section->addText('Lead text.');
+$footnote = $section->addFootnote();
+$footnote->addText('Footnote text.');
+```
+
+The footnote reference number will be displayed with decimal number starting from 1. This number use `FooterReference` style which you can redefine by `addFontStyle` method. Default value for this style is `array('superScript' => true)`;
+
+## Checkboxes
+
+Checkbox elements can be added to sections or table cells by using `addCheckBox`.
+
+```php
+$section->addCheckBox($name, $text, [$fontStyle], [$paragraphStyle])
+```
+
+- `$name` Name of the check box.
+- `$text` Text following the check box
+- `$fontStyle` See "Font style" section.
+- `$paragraphStyle` See "Paragraph style" section.
+
+# Templates
+
+You can create a docx template with included search-patterns that can be replaced by any value you wish. Only single-line values can be replaced. To load a template file, use the `loadTemplate` method. After loading the docx template, you can use the `setValue` method to change the value of a search pattern. The search-pattern model is: `${search-pattern}`. It is not possible to add new PHPWord elements to a loaded template file.
+
+Example:
+
+```php
+$template = $phpWord->loadTemplate('Template.docx');
+$template->setValue('Name', 'Somebody someone');
+$template->setValue('Street', 'Coming-Undone-Street 32');
+```
+
+See `Sample_07_TemplateCloneRow.php` for example on how to create multirow from a single row in a template by using `cloneRow`.
+
+See `Sample_23_TemplateBlock.php` for example on how to clone a block of text using `cloneBlock` and delete a block of text using `deleteBlock`.
+
+# Writers & readers
+
+## OOXML
+
+The package of OOXML document consists of the following files.
+
+- _rels/
+ - .rels
+- docProps/
+ - app.xml
+ - core.xml
+ - custom.xml
+- word/
+ - rels/
+ - document.rels.xml
+ - media/
+ - theme/
+ - theme1.xml
+ - document.xml
+ - fontTable.xml
+ - numbering.xml
+ - settings.xml
+ - styles.xml
+ - webSettings.xml
+- [Content_Types].xml
+
+## OpenDocument
+
+### Package
+
+The package of OpenDocument document consists of the following files.
+
+- META-INF/
+ - manifest.xml
+- Pictures/
+- content.xml
+- meta.xml
+- styles.xml
+
+### content.xml
+
+The structure of `content.xml` is described below.
+
+- office:document-content
+ - office:font-facedecls
+ - office:automatic-styles
+ - office:body
+ - office:text
+ - draw:*
+ - office:forms
+ - table:table
+ - text:list
+ - text:numbered-paragraph
+ - text:p
+ - text:table-of-contents
+ - text:section
+ - office:chart
+ - office:image
+ - office:drawing
+
+### styles.xml
+
+The structure of `styles.xml` is described below.
+
+- office:document-styles
+ - office:styles
+ - office:automatic-styles
+ - office:master-styles
+ - office:master-page
+
+## RTF
+
+To be completed.
+
+## HTML
+
+To be completed.
+
+## PDF
+
+To be completed.
+
+# Frequently asked questions
+
+## Is this the same with PHPWord that I found in CodePlex?
+
+No. This one is much better with tons of new features that you can’t find in PHPWord 0.6.3. The development in CodePlex is halted and switched to GitHub to allow more participation from the crowd. The more the merrier, right?
+
+## I’ve been running PHPWord from CodePlex flawlessly, but I can’t use the latest PHPWord from GitHub. Why?
+
+PHPWord requires PHP 5.3+ since 0.8, while PHPWord 0.6.3 from CodePlex can run with PHP 5.2. There’s a lot of new features that we can get from PHP 5.3 and it’s been around since 2009! You should upgrade your PHP version to use PHPWord 0.8+.
+
+# References
+
+## Formal specifications
+
+- [Office Open XML (OOXML) (ECMA-376) Schema](http://www.schemacentral.com/sc/ooxml/ss.html)
+- [Oasis OpenDocument Standard Version 1.2](http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os.html)
+- [Rich Text Format (RTF) Specification, version 1.9.1](http://www.microsoft.com/en-us/download/details.aspx?id=10725)
+
+## Other resources
+
+- [DocumentFormat.OpenXml.Wordprocessing Namespace on MSDN](http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing%28v=office.14%29.aspx)
+
diff --git a/docs/templates.rst b/docs/templates.rst
index 6b627b06..b1d9d205 100644
--- a/docs/templates.rst
+++ b/docs/templates.rst
@@ -19,6 +19,9 @@ Example:
$template->setValue('Name', 'Somebody someone');
$template->setValue('Street', 'Coming-Undone-Street 32');
-See ``Sample_07_TemplateCloneRow.php`` for more code sample, including
-how to create multirow from a single row in a template by using
-``cloneRow``.
+See ``Sample_07_TemplateCloneRow.php`` for example on how to create
+multirow from a single row in a template by using ``cloneRow``.
+
+See ``Sample_23_TemplateBlock.php`` for example on how to clone a block
+of text using ``cloneBlock`` and delete a block of text using
+``deleteBlock``.
diff --git a/docs/writersreaders.rst b/docs/writersreaders.rst
new file mode 100644
index 00000000..34a0805a
--- /dev/null
+++ b/docs/writersreaders.rst
@@ -0,0 +1,110 @@
+.. _writersreaders:
+
+Writers & readers
+=================
+
+OOXML
+-----
+
+The package of OOXML document consists of the following files.
+
+- \_rels/
+
+ - .rels
+
+- docProps/
+
+ - app.xml
+ - core.xml
+ - custom.xml
+
+- word/
+
+ - rels/
+
+ - document.rels.xml
+
+ - media/
+ - theme/
+
+ - theme1.xml
+
+ - document.xml
+ - fontTable.xml
+ - numbering.xml
+ - settings.xml
+ - styles.xml
+ - webSettings.xml
+
+- [Content\_Types].xml
+
+OpenDocument
+------------
+
+Package
+~~~~~~~
+
+The package of OpenDocument document consists of the following files.
+
+- META-INF/
+
+ - manifest.xml
+
+- Pictures/
+- content.xml
+- meta.xml
+- styles.xml
+
+content.xml
+~~~~~~~~~~~
+
+The structure of ``content.xml`` is described below.
+
+- office:document-content
+
+ - office:font-facedecls
+ - office:automatic-styles
+ - office:body
+
+ - office:text
+
+ - draw:\*
+ - office:forms
+ - table:table
+ - text:list
+ - text:numbered-paragraph
+ - text:p
+ - text:table-of-contents
+ - text:section
+
+ - office:chart
+ - office:image
+ - office:drawing
+
+styles.xml
+~~~~~~~~~~
+
+The structure of ``styles.xml`` is described below.
+
+- office:document-styles
+
+ - office:styles
+ - office:automatic-styles
+ - office:master-styles
+
+ - office:master-page
+
+RTF
+---
+
+To be completed.
+
+HTML
+----
+
+To be completed.
+
+PDF
+---
+
+To be completed.
diff --git a/phpmd.xml b/phpmd.xml
new file mode 100644
index 00000000..c1ebb770
--- /dev/null
+++ b/phpmd.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 05b08442..f77b9ce3 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -16,6 +16,9 @@
./src
+
+ ./src/PhpWord/Shared/PCLZip
+
\ No newline at end of file
diff --git a/samples/Sample_01_SimpleText.php b/samples/Sample_01_SimpleText.php
old mode 100755
new mode 100644
index 7ada399a..7202ed7e
--- a/samples/Sample_01_SimpleText.php
+++ b/samples/Sample_01_SimpleText.php
@@ -2,14 +2,14 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , " Create new PhpWord object" , \EOL;
+echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16));
+$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Simple text
$section->addTitle('Welcome to PhpWord', 1);
@@ -34,6 +34,7 @@ $fontStyle['strikethrough'] = true;
$fontStyle['superScript'] = true;
$fontStyle['color'] = 'FF0000';
$fontStyle['fgColor'] = 'yellow';
+$fontStyle['smallCaps'] = true;
$section->addText('I am inline styled.', $fontStyle);
$section->addTextBreak();
@@ -45,13 +46,7 @@ $section->addTextBreak();
$section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_02_TabStops.php b/samples/Sample_02_TabStops.php
old mode 100755
new mode 100644
index f08f1e15..d6e4cdbc
--- a/samples/Sample_02_TabStops.php
+++ b/samples/Sample_02_TabStops.php
@@ -2,7 +2,7 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
+echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Ads styles
@@ -25,21 +25,15 @@ $phpWord->addParagraphStyle('centerTab', array(
));
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add listitem elements
-$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');
-$section->addText("Left Aligned\tRight Aligned", NULL, 'rightTab');
-$section->addText("\tCenter Aligned", NULL, 'centerTab');
+$section->addText("Multiple Tabs:\tOne\tTwo\tThree", null, 'multipleTab');
+$section->addText("Left Aligned\tRight Aligned", null, 'rightTab');
+$section->addText("\tCenter Aligned", null, 'centerTab');
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php
old mode 100755
new mode 100644
index c16b73db..bfbc84af
--- a/samples/Sample_03_Sections.php
+++ b/samples/Sample_03_Sections.php
@@ -2,37 +2,31 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
+echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
-$section = $phpWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
+$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section->addText('I am placed on a default section.');
// New landscape section
-$section = $phpWord->createSection(array('orientation' => 'landscape'));
+$section = $phpWord->addSection(array('orientation' => 'landscape'));
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
$section->addPageBreak();
$section->addPageBreak();
// New portrait section
-$section = $phpWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
+$section = $phpWord->addSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins.');
// New portrait section with Header & Footer
-$section = $phpWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
+$section = $phpWord->addSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
$section->addText('This section and we play with header/footer height.');
-$section->createHeader()->addText('Header');
-$section->createFooter()->addText('Footer');
+$section->addHeader()->addText('Header');
+$section->addFooter()->addText('Footer');
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_04_Textrun.php b/samples/Sample_04_Textrun.php
index 94bc3d5b..e41f4ddb 100644
--- a/samples/Sample_04_Textrun.php
+++ b/samples/Sample_04_Textrun.php
@@ -2,20 +2,20 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
+echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Ads styles
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
$phpWord->addFontStyle('BoldText', array('bold'=>true));
-$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
+$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080', 'bgColor' => 'FFFFCC'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add text run
-$textrun = $section->createTextRun('pStyle');
+$textrun = $section->addTextRun('pStyle');
$textrun->addText('Each textrun can contain native text, link elements or an image.');
$textrun->addText(' No break is placed after adding an element.', 'BoldText');
@@ -28,17 +28,13 @@ $textrun->addText(' All elements are placed inside a paragraph with the optional
$textrun->addText(' Sample Link: ');
$textrun->addLink('http://www.google.com', null, 'NLink');
$textrun->addText(' Sample Image: ');
-$textrun->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
+$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
+$textrun->addText(' Sample Object: ');
+$textrun->addObject('resources/_sheet.xls');
$textrun->addText(' Here is some more text. ');
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_05_Multicolumn.php b/samples/Sample_05_Multicolumn.php
index 541e2e8a..a3083824 100644
--- a/samples/Sample_05_Multicolumn.php
+++ b/samples/Sample_05_Multicolumn.php
@@ -2,7 +2,7 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , " Create new PhpWord object" , \EOL;
+echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' .
@@ -10,39 +10,33 @@ $filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
'Suspendisse congue congue leo sed pellentesque.';
// Normal
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Normal paragraph. ' . $filler);
// Two columns
-$section = $phpWord->createSection(array(
+$section = $phpWord->addSection(array(
'colsNum' => 2,
'colsSpace' => 1440,
'breakType' => 'continuous'));
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
// Normal
-$section = $phpWord->createSection(array('breakType' => 'continuous'));
+$section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again. ' . $filler);
// Three columns
-$section = $phpWord->createSection(array(
+$section = $phpWord->addSection(array(
'colsNum' => 3,
'colsSpace' => 720,
'breakType' => 'continuous'));
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
// Normal
-$section = $phpWord->createSection(array('breakType' => 'continuous'));
+$section = $phpWord->addSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again.');
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_06_Footnote.php b/samples/Sample_06_Footnote.php
old mode 100755
new mode 100644
index c430e548..1bec44e4
--- a/samples/Sample_06_Footnote.php
+++ b/samples/Sample_06_Footnote.php
@@ -2,11 +2,12 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , " Create new PhpWord object" , \EOL;
+echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
+\PhpOffice\PhpWord\Settings::setCompatibility(false);
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add style definitions
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
@@ -15,32 +16,29 @@ $phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// Add text elements
-$textrun = $section->createTextRun('pStyle');
+$textrun = $section->addTextRun('pStyle');
$textrun->addText('This is some lead text in a paragraph with a following footnote. ','pStyle');
-$footnote = $textrun->createFootnote();
-$footnote->addText('Just like a textrun a footnote can contain native text and link elements.');
-$footnote->addText(' No break is placed after adding an element.', 'BoldText');
-$footnote->addText(' All elements are placed inside a paragraph.', 'ColoredText');
-$footnote->addText(' The best search engine: ');
+$footnote = $textrun->addFootnote();
+$footnote->addText('Just like a textrun, a footnote can contain native texts. ');
+$footnote->addText('No break is placed after adding an element. ', 'BoldText');
+$footnote->addText('All elements are placed inside a paragraph. ', 'ColoredText');
+$footnote->addTextBreak();
+$footnote->addText('But you can insert a manual text break like above, ');
+$footnote->addText('links like ');
$footnote->addLink('http://www.google.com', null, 'NLink');
-$footnote->addText('. Also not bad: ');
-$footnote->addLink('http://www.bing.com', null, 'NLink');
-
-$textrun->addText('The trailing text in the paragraph.');
+$footnote->addText(', image like ');
+$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
+$footnote->addText(', or object like ');
+$footnote->addObject('resources/_sheet.xls');
+$footnote->addText('But you can only put footnote in section, not in header or footer.');
$section->addText('You can also create the footnote directly from the section making it wrap in a paragraph like the footnote below this paragraph. But is is best used from within a textrun.');
-$footnote = $section->createFootnote();
+$footnote = $section->addFootnote();
$footnote->addText('The reference for this is wrapped in its own line');
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_07_TemplateCloneRow.php b/samples/Sample_07_TemplateCloneRow.php
old mode 100755
new mode 100644
index 4344fafc..899bc82b
--- a/samples/Sample_07_TemplateCloneRow.php
+++ b/samples/Sample_07_TemplateCloneRow.php
@@ -2,11 +2,16 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s') , " Create new PhpWord object" , \EOL;
+echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$document = $phpWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
+// Variables on different parts of document
+$document->setValue('weekday', date('l')); // On section/content
+$document->setValue('time', date('H:i')); // On footer
+$document->setValue('serverName', realpath(__DIR__)); // On header
+
// Simple table
$document->cloneRow('rowValue', 10);
@@ -32,9 +37,6 @@ $document->setValue('rowNumber#8', '8');
$document->setValue('rowNumber#9', '9');
$document->setValue('rowNumber#10', '10');
-$document->setValue('weekday', date('l'));
-$document->setValue('time', date('H:i'));
-
// Table with a spanned cell
$document->cloneRow('userId', 3);
@@ -54,8 +56,11 @@ $document->setValue('userName#3', 'Ray');
$document->setValue('userPhone#3', '+1 428 889 775');
$name = 'Sample_07_TemplateCloneRow.docx';
-echo date('H:i:s'), " Write to Word2007 format", \EOL;
+echo date('H:i:s'), " Write to Word2007 format", EOL;
$document->saveAs($name);
rename($name, "results/{$name}");
-include_once 'Sample_Footer.php';
+echo getEndingNotes(array('Word2007' => 'docx'));
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_08_ParagraphPagination.php b/samples/Sample_08_ParagraphPagination.php
index eeef6058..d3f0c1fb 100644
--- a/samples/Sample_08_ParagraphPagination.php
+++ b/samples/Sample_08_ParagraphPagination.php
@@ -2,7 +2,7 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s') , " Create new PhpWord object" , \EOL;
+echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(array(
'align' => 'both',
@@ -11,31 +11,31 @@ $phpWord->setDefaultParagraphStyle(array(
));
// Sample
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Below are the samples on how to control your paragraph ' .
'pagination. See "Line and Page Break" tab on paragraph properties ' .
'window to see the attribute set by these controls.',
- array('bold' => true), null);
+ array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
$section->addText('Paragraph with widowControl = false (default: true). ' .
'A "widow" is the last line of a paragraph printed by itself at the top ' .
'of a page. An "orphan" is the first line of a paragraph printed by ' .
'itself at the bottom of a page. Set this option to "false" if you want ' .
'to disable this automatic control.',
- null, array('widowControl' => false));
+ null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
$section->addText('Paragraph with keepNext = true (default: false). ' .
'"Keep with next" is used to prevent Word from inserting automatic page ' .
'breaks between paragraphs. Set this option to "true" if you do not want ' .
'your paragraph to be separated with the next paragraph.',
- null, array('keepNext' => true));
+ null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
$section->addText('Paragraph with keepLines = true (default: false). ' .
'"Keep lines together" will prevent Word from inserting an automatic page ' .
'break within a paragraph. Set this option to "true" if you do not want ' .
'all lines of your paragraph to be in the same page.',
- null, array('keepLines' => true));
+ null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
$section->addText('Keep scrolling. More below.');
@@ -46,13 +46,7 @@ $section->addText('Paragraph with pageBreakBefore = true (default: false). ' .
null, array('pageBreakBefore' => true));
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_09_Tables.php b/samples/Sample_09_Tables.php
index ea10eec9..5b4b1300 100644
--- a/samples/Sample_09_Tables.php
+++ b/samples/Sample_09_Tables.php
@@ -2,9 +2,9 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
+echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
// 1. Basic table
@@ -55,7 +55,7 @@ $section->addTextBreak(1);
$section->addText("Table with colspan and rowspan", $header);
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
-$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center');
+$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00');
$cellRowContinue = array('vMerge' => 'continue');
$cellColSpan = array('gridSpan' => 2, 'valign' => 'center');
$cellHCentered = array('align' => 'center');
@@ -63,10 +63,21 @@ $cellVCentered = array('valign' => 'center');
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan');
+
$table->addRow();
-$table->addCell(2000, $cellRowSpan)->addText('A', null, $cellHCentered);
-$table->addCell(4000, $cellColSpan)->addText('B', null, $cellHCentered);
+
+$cell1 = $table->addCell(2000, $cellRowSpan);
+$textrun1 = $cell1->addTextRun($cellHCentered);
+$textrun1->addText('A');
+$textrun1->addFootnote()->addText('Row span');
+
+$cell2 = $table->addCell(4000, $cellColSpan);
+$textrun2 = $cell2->addTextRun($cellHCentered);
+$textrun2->addText('B');
+$textrun2->addFootnote()->addText('Colspan span');
+
$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered);
+
$table->addRow();
$table->addCell(null, $cellRowContinue);
$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
@@ -74,13 +85,7 @@ $table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered);
$table->addCell(null, $cellRowContinue);
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_10_EastAsianFontStyle.php b/samples/Sample_10_EastAsianFontStyle.php
index 6e8b26a0..44bca8a6 100644
--- a/samples/Sample_10_EastAsianFontStyle.php
+++ b/samples/Sample_10_EastAsianFontStyle.php
@@ -2,21 +2,15 @@
include_once 'Sample_Header.php';
// New Word Document
-echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
+echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_11_ReadWord2007.php b/samples/Sample_11_ReadWord2007.php
index b2420a53..09d9cab0 100644
--- a/samples/Sample_11_ReadWord2007.php
+++ b/samples/Sample_11_ReadWord2007.php
@@ -4,16 +4,11 @@ include_once 'Sample_Header.php';
// Read contents
$name = basename(__FILE__, '.php');
$source = "resources/{$name}.docx";
-echo date('H:i:s'), " Reading contents from `{$source}`", \EOL;
+echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
-// (Re)write contents
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_12_HeaderFooter.php b/samples/Sample_12_HeaderFooter.php
index 3c5775ef..8e053286 100644
--- a/samples/Sample_12_HeaderFooter.php
+++ b/samples/Sample_12_HeaderFooter.php
@@ -2,30 +2,34 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s') , " Create new PhpWord object" , \EOL;
+echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add first page header
-$header = $section->createHeader();
+$header = $section->addHeader();
$header->firstPage();
$table = $header->addTable();
$table->addRow();
-$table->addCell(4500)->addText('This is the header.');
+$cell = $table->addCell(4500);
+$textrun = $cell->addTextRun();
+$textrun->addText('This is the header with ');
+$textrun->addLink('http://google.com', 'link to Google');
$table->addCell(4500)->addImage(
'resources/PhpWord.png',
array('width' => 80, 'height' => 80, 'align' => 'right')
);
// Add header for all other pages
-$subsequent = $section->createHeader();
+$subsequent = $section->addHeader();
$subsequent->addText("Subsequent pages in Section 1 will Have this!");
// Add footer
-$footer = $section->createFooter();
+$footer = $section->addFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center'));
+$footer->addLink('http://google.com', 'Direct Google');
// Write some text
$section->addTextBreak();
@@ -46,24 +50,17 @@ $section->addTextBreak();
$section->addText('Some text...');
// New portrait section
-$section2 = $phpWord->createSection();
+$section2 = $phpWord->addSection();
-$sec2Header = $section2->createHeader();
+$sec2Header = $section2->addHeader();
$sec2Header->addText("All pages in Section 2 will Have this!");
// Write some text
$section2->addTextBreak();
$section2->addText('Some text...');
-
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_13_Images.php b/samples/Sample_13_Images.php
index 6841ed64..65e38bf5 100644
--- a/samples/Sample_13_Images.php
+++ b/samples/Sample_13_Images.php
@@ -2,32 +2,37 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s'), " Create new PhpWord object", \EOL;
+echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg');
$section->addTextBreak(2);
-//
+
$section->addText('Local image with styles:');
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
$section->addTextBreak(2);
+// Remote image
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
$section->addText("Remote image from: {$source}");
-$section->addMemoryImage($source);
-// End code
+$section->addImage($source);
-// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+//Wrapping style
+$text = str_repeat('Hello World! ', 15);
+$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
+foreach ($wrappingStyles as $wrappingStyle) {
+ $section->addTextBreak(5);
+ $section->addText('Wrapping style ' . $wrappingStyle);
+ $section->addImage('resources/_earth.jpg', array('marginTop' => -1, 'marginLeft' => 1,
+ 'width' => 80, 'height' => 80, 'wrappingStyle' => $wrappingStyle));
+ $section->addText($text);
}
-include_once 'Sample_Footer.php';
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_14_ListItem.php b/samples/Sample_14_ListItem.php
index 45cb73ab..cd22df8e 100644
--- a/samples/Sample_14_ListItem.php
+++ b/samples/Sample_14_ListItem.php
@@ -2,56 +2,60 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s'), " Create new PhpWord object", \EOL;
+echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
-// Add listitem elements
-$section->addListItem('List Item 1', 0);
-$section->addListItem('List Item 2', 0);
-$section->addListItem('List Item 3', 0);
-$section->addTextBreak(2);
+// Style definition
-// Add listitem elements
-$section->addListItem('List Item 1', 0);
-$section->addListItem('List Item 1.1', 1);
-$section->addListItem('List Item 1.2', 1);
-$section->addListItem('List Item 1.3 (styled)', 1, array('bold'=>true));
-$section->addListItem('List Item 1.3.1', 2);
-$section->addListItem('List Item 1.3.2', 2);
-$section->addTextBreak(2);
-
-// Add listitem elements
-$listStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER);
-$section->addListItem('List Item 1', 0, null, $listStyle);
-$section->addListItem('List Item 2', 0, null, $listStyle);
-$section->addListItem('List Item 3', 0, null, $listStyle);
-$section->addTextBreak(2);
-
-// Add listitem elements
$phpWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
$phpWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
-$listStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
-$section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style');
-$section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style');
-$section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style');
-$section->addListItem('List Item 4', 1, 'myOwnStyle', $listStyle, 'P-Style');
-$section->addListItem('List Item 5', 2, 'myOwnStyle', $listStyle, 'P-Style');
-$section->addListItem('List Item 6', 1, 'myOwnStyle', $listStyle, 'P-Style');
-$section->addListItem('List Item 7', 0, 'myOwnStyle', $listStyle, 'P-Style');
+$phpWord->addNumberingStyle(
+ 'multilevel',
+ array('type' => 'multilevel', 'levels' => array(
+ array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
+ array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
+ )
+ )
+);
+$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
-// End code
+// Lists
+
+$section->addText('Multilevel list.');
+$section->addListItem('List Item I', 0, null, 'multilevel');
+$section->addListItem('List Item I.a', 1, null, 'multilevel');
+$section->addListItem('List Item I.b', 1, null, 'multilevel');
+$section->addListItem('List Item II', 0, null, 'multilevel');
+$section->addListItem('List Item II.a', 1, null, 'multilevel');
+$section->addListItem('List Item III', 0, null, 'multilevel');
+$section->addTextBreak(2);
+
+$section->addText('Basic simple bulleted list.');
+$section->addListItem('List Item 1');
+$section->addListItem('List Item 2');
+$section->addListItem('List Item 3');
+$section->addTextBreak(2);
+
+$section->addText('Continue from multilevel list above.');
+$section->addListItem('List Item IV', 0, null, 'multilevel');
+$section->addListItem('List Item IV.a', 1, null, 'multilevel');
+$section->addTextBreak(2);
+
+$section->addText('Multilevel predefined list.');
+$section->addListItem('List Item 1', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
+$section->addListItem('List Item 2', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
+$section->addListItem('List Item 3', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
+$section->addListItem('List Item 4', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
+$section->addListItem('List Item 5', 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
+$section->addListItem('List Item 6', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
+$section->addListItem('List Item 7', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
+$section->addTextBreak(2);
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_15_Link.php b/samples/Sample_15_Link.php
index 06628de5..1bd61e79 100644
--- a/samples/Sample_15_Link.php
+++ b/samples/Sample_15_Link.php
@@ -2,11 +2,11 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s'), " Create new PhpWord object", \EOL;
+echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Add hyperlink elements
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
@@ -16,16 +16,8 @@ $phpWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'))
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
-// End code
-
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_16_Object.php b/samples/Sample_16_Object.php
index 1a7f557a..af23a00f 100644
--- a/samples/Sample_16_Object.php
+++ b/samples/Sample_16_Object.php
@@ -2,25 +2,17 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s'), " Create new PhpWord object", \EOL;
+echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
$section->addObject('resources/_sheet.xls');
-// End code
-
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_17_TitleTOC.php b/samples/Sample_17_TitleTOC.php
index 27982921..b18b1bc9 100644
--- a/samples/Sample_17_TitleTOC.php
+++ b/samples/Sample_17_TitleTOC.php
@@ -2,25 +2,41 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s'), " Create new PhpWord object", \EOL;
+echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
// Define the TOC font style
-$fontStyle = array('spaceAfter'=>60, 'size'=>12);
+$fontStyle = array('spaceAfter' => 60, 'size' => 12);
+$fontStyle2 = array('size' => 10);
// Add title styles
-$phpWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
-$phpWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
+$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
+$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
+$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
+$phpWord->addTitleStyle(4, array('size' => 12));
// Add text elements
-$section->addText('Table of contents:');
+$section->addText('Table of contents 1');
$section->addTextBreak(2);
-// Add TOC
-$section->addTOC($fontStyle);
+// Add TOC #1
+$toc = $section->addTOC($fontStyle);
+$section->addTextBreak(2);
+
+// Filler
+$section->addText('Text between TOC');
+$section->addTextBreak(2);
+
+// Add TOC #1
+$section->addText('Table of contents 2');
+$section->addTextBreak(2);
+$toc2 = $section->addTOC($fontStyle2);
+$toc2->setMinDepth(2);
+$toc2->setMaxDepth(3);
+
// Add Titles
$section->addPageBreak();
@@ -41,18 +57,19 @@ $section->addText('And more text...');
$section->addTextBreak(2);
$section->addTitle('I am a Subtitle of Title 3', 2);
$section->addText('Again and again, more text...');
+$section->addTitle('Subtitle 3.1.1', 3);
+$section->addText('Text');
+$section->addTitle('Subtitle 3.1.1.1', 4);
+$section->addText('Text');
+$section->addTitle('Subtitle 3.1.1.2', 4);
+$section->addText('Text');
+$section->addTitle('Subtitle 3.1.2', 3);
+$section->addText('Text');
-echo date('H:i:s'), " Note: Please refresh TOC manually.", \EOL;
-// End code
+echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL;
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_18_Watermark.php b/samples/Sample_18_Watermark.php
index ff299c97..313cfbed 100644
--- a/samples/Sample_18_Watermark.php
+++ b/samples/Sample_18_Watermark.php
@@ -2,26 +2,18 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s'), " Create new PhpWord object", \EOL;
+echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
-$section = $phpWord->createSection();
-$header = $section->createHeader();
+$section = $phpWord->addSection();
+$header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
$section->addText('The header reference to the current section includes a watermark image.');
-// End code
-
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_19_TextBreak.php b/samples/Sample_19_TextBreak.php
index 9433222c..a209ce39 100644
--- a/samples/Sample_19_TextBreak.php
+++ b/samples/Sample_19_TextBreak.php
@@ -2,7 +2,7 @@
include_once 'Sample_Header.php';
// New Word document
-echo date('H:i:s'), " Create new PhpWord object", \EOL;
+echo date('H:i:s'), " Create new PhpWord object", EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
@@ -12,7 +12,7 @@ $phpWord->addFontStyle('fontStyle', array('size' => 9));
$phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
$fontStyle = array('size' => 24);
-$section = $phpWord->createSection();
+$section = $phpWord->addSection();
$section->addText('Text break with no style:');
$section->addTextBreak();
$section->addText('Text break with defined font style:');
@@ -25,16 +25,8 @@ $section->addText('Text break with inline paragraph style:');
$section->addTextBreak(1, null, $paragraphStyle);
$section->addText('Done.');
-// End code
-
// Save file
-$name = basename(__FILE__, '.php');
-$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
-foreach ($writers as $writer => $extension) {
- echo date('H:i:s'), " Write to {$writer} format", \EOL;
- $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
- $xmlWriter->save("{$name}.{$extension}");
- rename("{$name}.{$extension}", "results/{$name}.{$extension}");
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
}
-
-include_once 'Sample_Footer.php';
diff --git a/samples/Sample_20_BGColor.php b/samples/Sample_20_BGColor.php
new file mode 100644
index 00000000..892cd8b2
--- /dev/null
+++ b/samples/Sample_20_BGColor.php
@@ -0,0 +1,17 @@
+addSection();
+
+$section->addText("This is some text highlighted using fgColor (limited to 15 colors) ", array("fgColor" => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW));
+$section->addText("This one uses bgColor and is using hex value (0xfbbb10)", array("bgColor" => "fbbb10"));
+$section->addText("Compatible with font colors", array("color"=>"0000ff", "bgColor" => "fbbb10"));
+
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_21_TableRowRules.php b/samples/Sample_21_TableRowRules.php
new file mode 100644
index 00000000..b600ec00
--- /dev/null
+++ b/samples/Sample_21_TableRowRules.php
@@ -0,0 +1,34 @@
+addSection();
+
+$section->addText("By default, when you insert an image, it adds a textbreak after its content.");
+$section->addText("If we want a simple border around an image, we wrap the image inside a table->row->cell");
+$section->addText("On the image with the red border, even if we set the row height to the height of the image, the textbreak is still there:");
+
+$table1 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
+$table1->addRow(3750);
+$cell1 = $table1->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "ff0000"));
+$cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
+
+$section->addTextBreak();
+$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:");
+
+$table2 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
+$table2->addRow(3750, array("exactHeight" => true));
+$cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00"));
+$cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
+
+$section->addTextBreak();
+$section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.");
+$section->addText("So: $"."table2->addRow(3750, array('exactHeight'=>true));");
+
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_22_CheckBox.php b/samples/Sample_22_CheckBox.php
new file mode 100644
index 00000000..e7aae5ba
--- /dev/null
+++ b/samples/Sample_22_CheckBox.php
@@ -0,0 +1,21 @@
+addSection();
+$section->addText('Check box in section');
+$section->addCheckBox('chkBox1', 'Checkbox 1');
+$section->addText('Check box in table cell');
+$table = $section->addTable();
+$table->addRow();
+$cell = $table->addCell();
+$cell->addCheckBox('chkBox2', 'Checkbox 2');
+
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_23_TemplateBlock.php b/samples/Sample_23_TemplateBlock.php
new file mode 100644
index 00000000..8ee8fc6d
--- /dev/null
+++ b/samples/Sample_23_TemplateBlock.php
@@ -0,0 +1,24 @@
+loadTemplate('resources/Sample_23_TemplateBlock.docx');
+
+// Will clone everything between ${tag} and ${/tag}, the number of times. By default, 1.
+$document->cloneBlock('CLONEME', 3);
+
+// Everything between ${tag} and ${/tag}, will be deleted/erased.
+$document->deleteBlock('DELETEME');
+
+$name = 'Sample_23_TemplateBlock.docx';
+echo date('H:i:s'), " Write to Word2007 format", EOL;
+$document->saveAs($name);
+rename($name, "results/{$name}");
+
+echo getEndingNotes(array('Word2007' => 'docx'));
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_24_ReadODText.php b/samples/Sample_24_ReadODText.php
new file mode 100644
index 00000000..bb5332e6
--- /dev/null
+++ b/samples/Sample_24_ReadODText.php
@@ -0,0 +1,14 @@
+
';
- echo 'Results: ';
- foreach ($types as $type) {
- $result = "results/{$sampleFile}.{$type}";
- if (file_exists($result)) {
- echo "{$type} ";
- }
- }
- echo '
';
- }
?>