Added section page numbering
This commit is contained in:
parent
3cf069fc46
commit
617feb3240
|
|
@ -150,6 +150,14 @@ class PHPWord_Section_Settings
|
|||
*/
|
||||
private $_borderBottomColor;
|
||||
|
||||
|
||||
/**
|
||||
* Page Numbering Start
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $pageNumberingStart;
|
||||
|
||||
/**
|
||||
* Create new Section Settings
|
||||
*/
|
||||
|
|
@ -542,4 +550,22 @@ class PHPWord_Section_Settings
|
|||
{
|
||||
return $this->_borderBottomColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|int $pageNumberingStart
|
||||
* @return $this
|
||||
*/
|
||||
public function setPageNumberingStart($pageNumberingStart = null)
|
||||
{
|
||||
$this->pageNumberingStart = $pageNumberingStart;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|int
|
||||
*/
|
||||
public function getPageNumberingStart()
|
||||
{
|
||||
return $this->pageNumberingStart;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,19 +123,19 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
|
|||
|
||||
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
|
||||
{
|
||||
$_settings = $section->getSettings();
|
||||
$settings = $section->getSettings();
|
||||
$_headers = $section->getHeaders();
|
||||
$_footer = $section->getFooter();
|
||||
$pgSzW = $_settings->getPageSizeW();
|
||||
$pgSzH = $_settings->getPageSizeH();
|
||||
$orientation = $_settings->getOrientation();
|
||||
$pgSzW = $settings->getPageSizeW();
|
||||
$pgSzH = $settings->getPageSizeH();
|
||||
$orientation = $settings->getOrientation();
|
||||
|
||||
$marginTop = $_settings->getMarginTop();
|
||||
$marginLeft = $_settings->getMarginLeft();
|
||||
$marginRight = $_settings->getMarginRight();
|
||||
$marginBottom = $_settings->getMarginBottom();
|
||||
$marginTop = $settings->getMarginTop();
|
||||
$marginLeft = $settings->getMarginLeft();
|
||||
$marginRight = $settings->getMarginRight();
|
||||
$marginBottom = $settings->getMarginBottom();
|
||||
|
||||
$borders = $_settings->getBorderSize();
|
||||
$borders = $settings->getBorderSize();
|
||||
|
||||
$objWriter->startElement('w:sectPr');
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
|
|||
|
||||
|
||||
if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
|
||||
$borderColor = $_settings->getBorderColor();
|
||||
$borderColor = $settings->getBorderColor();
|
||||
|
||||
$objWriter->startElement('w:pgBorders');
|
||||
$objWriter->writeAttribute('w:offsetFrom', 'page');
|
||||
|
|
@ -225,6 +225,12 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
|
|||
$objWriter->endElement();
|
||||
}
|
||||
|
||||
// Page numbering
|
||||
if (null !== $settings->getPageNumberingStart()) {
|
||||
$objWriter->startElement('w:pgNumType');
|
||||
$objWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart());
|
||||
$objWriter->endElement();
|
||||
}
|
||||
|
||||
$objWriter->startElement('w:cols');
|
||||
$objWriter->writeAttribute('w:space', '720');
|
||||
|
|
|
|||
59
README.md
59
README.md
|
|
@ -1,19 +1,18 @@
|
|||
# PHPWord - OpenXML - Read, Write and Create Word documents in PHP
|
||||
# PHPWord
|
||||
|
||||
__OpenXML - Read, Write and Create Word documents in PHP.__
|
||||
|
||||
PHPWord is a library written in PHP that create word documents.
|
||||
|
||||
PHPWord is a library written in PHP that create word documents.
|
||||
No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be
|
||||
opened by all major office software.
|
||||
|
||||
## Want to contribute?
|
||||
Fork us!
|
||||
__Want to contribute?__ Fork us!
|
||||
|
||||
## Requirements
|
||||
|
||||
* PHP version 5.3.0 or higher
|
||||
|
||||
## License
|
||||
PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md)
|
||||
|
||||
## Installation
|
||||
|
||||
It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add
|
||||
|
|
@ -27,7 +26,17 @@ the following lines to your ``composer.json``.
|
|||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
## Documentation
|
||||
|
||||
### Table of contents
|
||||
|
||||
1. [Basic usage](#basic-usage)
|
||||
2. [Sections](#sections)
|
||||
* [Change Section Page Numbering](#sections-page-numbering)
|
||||
3. [Images](#images)
|
||||
|
||||
<a name="basic-usage"></a>
|
||||
#### Basic usage
|
||||
|
||||
The following is a basic example of the PHPWord library.
|
||||
|
||||
|
|
@ -59,7 +68,21 @@ $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
|
|||
$objWriter->save('helloWorld.docx');
|
||||
```
|
||||
|
||||
## Images
|
||||
<a name="sections"></a>
|
||||
#### Sections
|
||||
|
||||
<a name="sections-page-numbering"></a>
|
||||
##### Change Section Page Numbering
|
||||
|
||||
You can change a section page numbering.
|
||||
|
||||
```php
|
||||
$section = $PHPWord->createSection();
|
||||
$section->getSettings()->setPageNumberingStart(1);
|
||||
```
|
||||
|
||||
<a name="images"></a>
|
||||
#### Images
|
||||
|
||||
You can add images easily using the following example.
|
||||
|
||||
|
|
@ -69,16 +92,16 @@ $section->addImage('mars.jpg');
|
|||
```
|
||||
|
||||
Images settings include:
|
||||
* ``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`` can be inline, __square__, __tight__, __behind__, __infront__
|
||||
* ``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`` can be _inline_, _square_, _tight_, _behind_, _infront_
|
||||
|
||||
To add an image with settings, consider the following example.
|
||||
To add an image with settings, consider the following example.
|
||||
|
||||
```php
|
||||
```php
|
||||
$section->addImage(
|
||||
'mars.jpg',
|
||||
array(
|
||||
|
|
@ -86,7 +109,7 @@ $section->addImage(
|
|||
'height' => 100,
|
||||
'marginTop' => -1,
|
||||
'marginLeft' => -1,
|
||||
wrappingStyle => 'behind'
|
||||
'wrappingStyle' => 'behind'
|
||||
)
|
||||
);
|
||||
```
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@
|
|||
* @version ##VERSION##, ##DATE##
|
||||
**************************************************************************************
|
||||
|
||||
Changes in branch for release 0.7.1 :
|
||||
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
|
||||
|
||||
Fixed in branch for release 0.7.0 :
|
||||
- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found
|
||||
- Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class ImageTest extends PHPUnit_Framework_TestCase
|
|||
public function testImageWrappingStyleBehind()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
$section = $PHPWord->createSection(12240, 15840, 0, 0, 0, 0);
|
||||
$section = $PHPWord->createSection();
|
||||
|
||||
$section->addImage(
|
||||
__DIR__ . '/_files/images/earth.jpg',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
namespace PHPWord\Tests\Section;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPWord;
|
||||
use PHPWord\Tests\TestHelper;
|
||||
|
||||
class PageNumberingTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function tearDown()
|
||||
{
|
||||
TestHelper::clear();
|
||||
}
|
||||
|
||||
public function testImageWrappingStyleBehind()
|
||||
{
|
||||
$PHPWord = new PHPWord();
|
||||
$section = $PHPWord->createSection();
|
||||
$section->getSettings()->setPageNumberingStart(2);
|
||||
|
||||
$doc = TestHelper::getDocument($PHPWord);
|
||||
$element = $doc->getElement('/w:document/w:body/w:sectPr/w:pgNumType');
|
||||
|
||||
$this->assertEquals(2, $element->getAttribute('w:start'));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue