Section: Ability to set paper size, e.g. A4, A3, and Legal

This commit is contained in:
Ivan Lanin 2014-06-06 15:23:19 +07:00
parent 49f4e6ba64
commit a2ec62a79f
7 changed files with 328 additions and 149 deletions

View File

@ -10,6 +10,7 @@ This is the changelog between releases of PHPWord. Releases are listed in revers
- Font: New `scale`, `spacing`, and `kerning` property of font style - @ivanlanin
- Paragraph: Added shading to the paragraph style for full width shading - @lrobert GH-264
- RTF Writer: Support for sections, margins, and borders - @ivanlanin GH-249
- Section: Ability to set paper size, e.g. A4, A3, and Legal - @ivanlanin GH-249
### Bugfixes

219
composer.lock generated
View File

@ -3,7 +3,7 @@
"This file locks the dependencies of your project to a known state",
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
],
"hash": "91993ff980d11a416fcf3a7309a4044f",
"hash": "7d0a883164ca8e64ca34f4910aa64b96",
"packages": [
],
@ -553,16 +553,16 @@
},
{
"name": "monolog/monolog",
"version": "1.9.1",
"version": "1.10.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "65026b610f8c19e61d7242f600530677b0466aac"
"reference": "25b16e801979098cb2f120e697bfce454b18bf23"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/65026b610f8c19e61d7242f600530677b0466aac",
"reference": "65026b610f8c19e61d7242f600530677b0466aac",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/25b16e801979098cb2f120e697bfce454b18bf23",
"reference": "25b16e801979098cb2f120e697bfce454b18bf23",
"shasum": ""
},
"require": {
@ -590,7 +590,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9.x-dev"
"dev-master": "1.10.x-dev"
}
},
"autoload": {
@ -617,7 +617,7 @@
"logging",
"psr-3"
],
"time": "2014-04-24 13:29:03"
"time": "2014-06-04 16:30:04"
},
{
"name": "mpdf/mpdf",
@ -1984,17 +1984,17 @@
},
{
"name": "symfony/config",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Config",
"source": {
"type": "git",
"url": "https://github.com/symfony/Config.git",
"reference": "2effc67af6f21a0d267210b72d0b0b691d113528"
"reference": "9c8caadb38ecc69ac35ab31af4d1996944b5a09f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Config/zipball/2effc67af6f21a0d267210b72d0b0b691d113528",
"reference": "2effc67af6f21a0d267210b72d0b0b691d113528",
"url": "https://api.github.com/repos/symfony/Config/zipball/9c8caadb38ecc69ac35ab31af4d1996944b5a09f",
"reference": "9c8caadb38ecc69ac35ab31af4d1996944b5a09f",
"shasum": ""
},
"require": {
@ -2004,7 +2004,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2030,36 +2030,38 @@
],
"description": "Symfony Config Component",
"homepage": "http://symfony.com",
"time": "2014-04-22 08:11:06"
"time": "2014-04-22 08:11:23"
},
{
"name": "symfony/console",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Console",
"source": {
"type": "git",
"url": "https://github.com/symfony/Console.git",
"reference": "2e452005b1e1d003d23702d227e23614679eb5ca"
"reference": "ef4ca73b0b3a10cbac653d3ca482d0cdd4502b2c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Console/zipball/2e452005b1e1d003d23702d227e23614679eb5ca",
"reference": "2e452005b1e1d003d23702d227e23614679eb5ca",
"url": "https://api.github.com/repos/symfony/Console/zipball/ef4ca73b0b3a10cbac653d3ca482d0cdd4502b2c",
"reference": "ef4ca73b0b3a10cbac653d3ca482d0cdd4502b2c",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"psr/log": "~1.0",
"symfony/event-dispatcher": "~2.1"
},
"suggest": {
"psr/log": "For using the console logger",
"symfony/event-dispatcher": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2085,28 +2087,31 @@
],
"description": "Symfony Console Component",
"homepage": "http://symfony.com",
"time": "2014-04-27 13:34:57"
"time": "2014-05-22 08:54:24"
},
{
"name": "symfony/event-dispatcher",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/EventDispatcher",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher.git",
"reference": "e539602e5455aa086c0e81e604745af7789e4d8a"
"reference": "cb62ec8dd05893fc8e4f0e6e21e326e1fc731fe8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/e539602e5455aa086c0e81e604745af7789e4d8a",
"reference": "e539602e5455aa086c0e81e604745af7789e4d8a",
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/cb62ec8dd05893fc8e4f0e6e21e326e1fc731fe8",
"reference": "cb62ec8dd05893fc8e4f0e6e21e326e1fc731fe8",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"symfony/dependency-injection": "~2.0"
"psr/log": "~1.0",
"symfony/config": "~2.0",
"symfony/dependency-injection": "~2.0",
"symfony/stopwatch": "~2.2"
},
"suggest": {
"symfony/dependency-injection": "",
@ -2115,7 +2120,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2141,21 +2146,21 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "http://symfony.com",
"time": "2014-04-16 10:34:31"
"time": "2014-04-29 10:13:57"
},
{
"name": "symfony/filesystem",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Filesystem",
"source": {
"type": "git",
"url": "https://github.com/symfony/Filesystem.git",
"reference": "a3af8294bcce4a7c1b2892363b0c9d8109affad4"
"reference": "98e831eac836a0a5911626ce82684155f21d0e4d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Filesystem/zipball/a3af8294bcce4a7c1b2892363b0c9d8109affad4",
"reference": "a3af8294bcce4a7c1b2892363b0c9d8109affad4",
"url": "https://api.github.com/repos/symfony/Filesystem/zipball/98e831eac836a0a5911626ce82684155f21d0e4d",
"reference": "98e831eac836a0a5911626ce82684155f21d0e4d",
"shasum": ""
},
"require": {
@ -2164,7 +2169,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2190,21 +2195,21 @@
],
"description": "Symfony Filesystem Component",
"homepage": "http://symfony.com",
"time": "2014-04-16 10:34:31"
"time": "2014-04-16 10:36:21"
},
{
"name": "symfony/finder",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Finder",
"source": {
"type": "git",
"url": "https://github.com/symfony/Finder.git",
"reference": "25e1e7d5e7376f8a92ae3b1d714d956edf33a730"
"reference": "307aad2c541bbdf43183043645e186ef2cd6b973"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Finder/zipball/25e1e7d5e7376f8a92ae3b1d714d956edf33a730",
"reference": "25e1e7d5e7376f8a92ae3b1d714d956edf33a730",
"url": "https://api.github.com/repos/symfony/Finder/zipball/307aad2c541bbdf43183043645e186ef2cd6b973",
"reference": "307aad2c541bbdf43183043645e186ef2cd6b973",
"shasum": ""
},
"require": {
@ -2213,7 +2218,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2239,21 +2244,21 @@
],
"description": "Symfony Finder Component",
"homepage": "http://symfony.com",
"time": "2014-04-27 13:34:57"
"time": "2014-05-22 13:47:45"
},
{
"name": "symfony/process",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Process",
"source": {
"type": "git",
"url": "https://github.com/symfony/Process.git",
"reference": "8721f1476d5d38a43c7d6ccb6435b351cf8f3bb7"
"reference": "5d7d78e23894544740219e006320678cfa4cd45b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Process/zipball/8721f1476d5d38a43c7d6ccb6435b351cf8f3bb7",
"reference": "8721f1476d5d38a43c7d6ccb6435b351cf8f3bb7",
"url": "https://api.github.com/repos/symfony/Process/zipball/5d7d78e23894544740219e006320678cfa4cd45b",
"reference": "5d7d78e23894544740219e006320678cfa4cd45b",
"shasum": ""
},
"require": {
@ -2262,7 +2267,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2288,81 +2293,21 @@
],
"description": "Symfony Process Component",
"homepage": "http://symfony.com",
"time": "2014-04-27 13:34:57"
},
{
"name": "symfony/property-access",
"version": "v2.4.4",
"target-dir": "Symfony/Component/PropertyAccess",
"source": {
"type": "git",
"url": "https://github.com/symfony/PropertyAccess.git",
"reference": "0456222bc00c40c1365065b603f7c397fb9a7134"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/PropertyAccess/zipball/0456222bc00c40c1365065b603f7c397fb9a7134",
"reference": "0456222bc00c40c1365065b603f7c397fb9a7134",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
}
},
"autoload": {
"psr-0": {
"Symfony\\Component\\PropertyAccess\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony PropertyAccess Component",
"homepage": "http://symfony.com",
"keywords": [
"access",
"array",
"extraction",
"index",
"injection",
"object",
"property",
"property path",
"reflection"
],
"time": "2014-04-18 20:37:09"
"time": "2014-05-23 09:02:52"
},
{
"name": "symfony/stopwatch",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Stopwatch",
"source": {
"type": "git",
"url": "https://github.com/symfony/Stopwatch.git",
"reference": "343bcc0360f2c22f371884b8f6a9fee8d1aa431a"
"reference": "724d73604ebe6c1c9bdf36533b556123bd9075a1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Stopwatch/zipball/343bcc0360f2c22f371884b8f6a9fee8d1aa431a",
"reference": "343bcc0360f2c22f371884b8f6a9fee8d1aa431a",
"url": "https://api.github.com/repos/symfony/Stopwatch/zipball/724d73604ebe6c1c9bdf36533b556123bd9075a1",
"reference": "724d73604ebe6c1c9bdf36533b556123bd9075a1",
"shasum": ""
},
"require": {
@ -2371,7 +2316,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2397,21 +2342,21 @@
],
"description": "Symfony Stopwatch Component",
"homepage": "http://symfony.com",
"time": "2014-04-18 20:37:09"
"time": "2014-04-18 20:40:13"
},
{
"name": "symfony/translation",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Translation",
"source": {
"type": "git",
"url": "https://github.com/symfony/Translation.git",
"reference": "d2c73ffa4a5ba1fa0c5d93f43b68331dffe898c5"
"reference": "5f23265dcf8927a84be832608069c9edca3cf5f4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Translation/zipball/d2c73ffa4a5ba1fa0c5d93f43b68331dffe898c5",
"reference": "d2c73ffa4a5ba1fa0c5d93f43b68331dffe898c5",
"url": "https://api.github.com/repos/symfony/Translation/zipball/5f23265dcf8927a84be832608069c9edca3cf5f4",
"reference": "5f23265dcf8927a84be832608069c9edca3cf5f4",
"shasum": ""
},
"require": {
@ -2428,7 +2373,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2454,48 +2399,53 @@
],
"description": "Symfony Translation Component",
"homepage": "http://symfony.com",
"time": "2014-04-18 21:02:05"
"time": "2014-05-22 13:47:45"
},
{
"name": "symfony/validator",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Validator",
"source": {
"type": "git",
"url": "https://github.com/symfony/Validator.git",
"reference": "5bbcdcc520bc7fb3826abb44020880f14c9c03a7"
"reference": "62f6f7735fbd3897b9347ae60fda4a40d0122640"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Validator/zipball/5bbcdcc520bc7fb3826abb44020880f14c9c03a7",
"reference": "5bbcdcc520bc7fb3826abb44020880f14c9c03a7",
"url": "https://api.github.com/repos/symfony/Validator/zipball/62f6f7735fbd3897b9347ae60fda4a40d0122640",
"reference": "62f6f7735fbd3897b9347ae60fda4a40d0122640",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"symfony/property-access": "~2.2",
"symfony/translation": "~2.0"
},
"require-dev": {
"doctrine/annotations": "~1.0",
"doctrine/cache": "~1.0",
"egulias/email-validator": "~1.0",
"symfony/config": "~2.2",
"symfony/expression-language": "~2.4",
"symfony/http-foundation": "~2.1",
"symfony/intl": "~2.3",
"symfony/property-access": "~2.2",
"symfony/yaml": "~2.0"
},
"suggest": {
"doctrine/annotations": "For using the annotation mapping. You will also need doctrine/cache.",
"doctrine/cache": "For using the default cached annotation reader",
"doctrine/cache": "For using the default cached annotation reader and metadata cache.",
"egulias/email-validator": "Strict (RFC compliant) email validation",
"symfony/config": "",
"symfony/expression-language": "For using the 2.4 Expression validator",
"symfony/http-foundation": "",
"symfony/intl": "",
"symfony/property-access": "For using the 2.4 Validator API",
"symfony/yaml": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2521,21 +2471,21 @@
],
"description": "Symfony Validator Component",
"homepage": "http://symfony.com",
"time": "2014-04-27 13:34:57"
"time": "2014-05-31 02:02:56"
},
{
"name": "symfony/yaml",
"version": "v2.4.4",
"version": "v2.5.0",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "65539ecde838f9c0d18b006b2101e3deb4b5c9ff"
"reference": "b4b09c68ec2f2727574544ef0173684281a5033c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/65539ecde838f9c0d18b006b2101e3deb4b5c9ff",
"reference": "65539ecde838f9c0d18b006b2101e3deb4b5c9ff",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/b4b09c68ec2f2727574544ef0173684281a5033c",
"reference": "b4b09c68ec2f2727574544ef0173684281a5033c",
"shasum": ""
},
"require": {
@ -2544,7 +2494,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
"dev-master": "2.5-dev"
}
},
"autoload": {
@ -2570,15 +2520,15 @@
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
"time": "2014-04-18 20:37:09"
"time": "2014-05-16 14:25:18"
},
{
"name": "tecnick.com/tcpdf",
"version": "6.0.078",
"version": "6.0.083",
"source": {
"type": "git",
"url": "git://git.code.sf.net/p/tcpdf/code",
"reference": "e1cbda79b99f3cdc8fdf26b39eb4870d2cd9fbac"
"reference": "d6a2206ab366f493680a22151429f17fd045fe04"
},
"require": {
"php": ">=5.3.0"
@ -2627,7 +2577,7 @@
"pdf417",
"qrcode"
],
"time": "2014-05-12 19:50:13"
"time": "2014-05-29 18:28:56"
},
{
"name": "twig/twig",
@ -3274,8 +3224,7 @@
],
"platform": {
"php": ">=5.3.3",
"ext-xml": "*",
"ext-zip": "*"
"ext-xml": "*"
},
"platform-dev": [

View File

@ -16,8 +16,8 @@ $section->addPageBreak();
$section->addPageBreak();
// New portrait section
$section = $phpWord->addSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins.');
$section = $phpWord->addSection(array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins with folio papersize.');
// New portrait section with Header & Footer
$section = $phpWord->addSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));

188
src/PhpWord/Style/Paper.php Normal file
View File

@ -0,0 +1,188 @@
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2010-2014 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Style;
/**
* Paper size from ISO/IEC 29500-1:2012 pg. 1656-1657
*
* 1 = Letter paper (8.5 in. by 11 in.)
* 2 = Letter small paper (8.5 in. by 11 in.)
* 3 = Tabloid paper (11 in. by 17 in.)
* 4 = Ledger paper (17 in. by 11 in.)
* 5 = Legal paper (8.5 in. by 14 in.)
* 6 = Statement paper (5.5 in. by 8.5 in.)
* 7 = Executive paper (7.25 in. by 10.5 in.)
* 8 = A3 paper (297 mm by 420 mm)
* 9 = A4 paper (210 mm by 297 mm)
* 10 = A4 small paper (210 mm by 297 mm)
* 11 = A5 paper (148 mm by 210 mm)
* 12 = B4 paper (250 mm by 353 mm)
* 13 = B5 paper (176 mm by 250 mm)
* 14 = Folio paper (8.5 in. by 13 in.)
* 15 = Quarto paper (215 mm by 275 mm)
* 16 = Standard paper (10 in. by 14 in.)
* 17 = Standard paper (11 in. by 17 in.)
* 18 = Note paper (8.5 in. by 11 in.)
* 19 = #9 envelope (3.875 in. by 8.875 in.)
* 20 = #10 envelope (4.125 in. by 9.5 in.)
* 21 = #11 envelope (4.5 in. by 10.375 in.)
* 22 = #12 envelope (4.75 in. by 11 in.)
* 23 = #14 envelope (5 in. by 11.5 in.)
* 24 = C paper (17 in. by 22 in.)
* 25 = D paper (22 in. by 34 in.)
* 26 = E paper (34 in. by 44 in.)
* 27 = DL envelope (110 mm by 220 mm)
* 28 = C5 envelope (162 mm by 229 mm)
* 29 = C3 envelope (324 mm by 458 mm)
* 30 = C4 envelope (229 mm by 324 mm)
* 31 = C6 envelope (114 mm by 162 mm)
* 32 = C65 envelope (114 mm by 229 mm)
* 33 = B4 envelope (250 mm by 353 mm)
* 34 = B5 envelope (176 mm by 250 mm)
* 35 = B6 envelope (176 mm by 125 mm)
* 36 = Italy envelope (110 mm by 230 mm)
* 37 = Monarch envelope (3.875 in. by 7.5 in.).
* 38 = 6 3/4 envelope (3.625 in. by 6.5 in.)
* 39 = US standard fanfold (14.875 in. by 11 in.)
* 40 = German standard fanfold (8.5 in. by 12 in.)
* 41 = German legal fanfold (8.5 in. by 13 in.)
* 42 = ISO B4 (250 mm by 353 mm)
* 43 = Japanese double postcard (200 mm by 148 mm)
* 44 = Standard paper (9 in. by 11 in.)
* 45 = Standard paper (10 in. by 11 in.)
* 46 = Standard paper (15 in. by 11 in.)
* 47 = Invite envelope (220 mm by 220 mm)
* 50 = Letter extra paper (9.275 in. by 12 in.)
* 51 = Legal extra paper (9.275 in. by 15 in.)
* 52 = Tabloid extra paper (11.69 in. by 18 in.)
* 53 = A4 extra paper (236 mm by 322 mm)
* 54 = Letter transverse paper (8.275 in. by 11 in.)
* 55 = A4 transverse paper (210 mm by 297 mm)
* 56 = Letter extra transverse paper (9.275 in. by 12 in.)
* 57 = SuperA/SuperA/A4 paper (227 mm by 356 mm)
* 58 = SuperB/SuperB/A3 paper (305 mm by 487 mm)
* 59 = Letter plus paper (8.5 in. by 12.69 in.)
* 60 = A4 plus paper (210 mm by 330 mm)
* 61 = A5 transverse paper (148 mm by 210 mm)
* 62 = JIS B5 transverse paper (182 mm by 257 mm)
* 63 = A3 extra paper (322 mm by 445 mm)
* 64 = A5 extra paper (174 mm by 235 mm)
* 65 = ISO B5 extra paper (201 mm by 276 mm)
* 66 = A2 paper (420 mm by 594 mm)
* 67 = A3 transverse paper (297 mm by 420 mm)
* 68 = A3 extra transverse paper (322 mm by 445 mm)
*
* @since 0.12.0
*/
class Paper extends AbstractStyle
{
/**
* Paper sizes
*
* @var array
*/
private $sizes = array(
'A3' => array(297, 420, 'mm'),
'A4' => array(210, 297, 'mm'),
'A5' => array(148, 210, 'mm'),
'Folio' => array(8.5, 13, 'in'),
'Legal' => array(8.5, 14, 'in'),
'Letter' => array(8.5, 11, 'in'),
);
/**
* Paper size
*
* @var string
*/
private $size = 'A4';
/**
* Width
*
* @var int (twip)
*/
private $width;
/**
* Height
*
* @var int (twip)
*/
private $height;
/**
* Create a new instance
*
* @param string $size
*/
public function __construct($size = 'A4')
{
$this->setSize($size);
}
/**
* Get size
*
* @return string
*/
public function getSize()
{
return $this->size;
}
/**
* Set size
*
* @param string $size
* @return self
*/
public function setSize($size)
{
$this->size = $this->setEnumVal($size, array_keys($this->sizes), $this->size);
list($width, $height, $unit) = $this->sizes[$this->size];
$multipliers = array('mm' => 56.5217, 'in' => 1440);
$multiplier = $multipliers[$unit];
$this->width = (int)round($width * $multiplier);
$this->height = (int)round($height * $multiplier);
return $this;
}
/**
* Get width
*
* @return int
*/
public function getWidth()
{
return $this->width;
}
/**
* Get height
*
* @return int
*/
public function getHeight()
{
return $this->height;
}
}

View File

@ -35,8 +35,8 @@ class Section extends Border
*
* @const int|float
*/
const DEFAULT_WIDTH = 11906; // In twip
const DEFAULT_HEIGHT = 16838; // In twip
const DEFAULT_WIDTH = 11870; // In twip
const DEFAULT_HEIGHT = 16787; // In twip
const DEFAULT_MARGIN = 1440; // In twip
const DEFAULT_GUTTER = 0; // In twip
const DEFAULT_HEADER_HEIGHT = 720; // In twip
@ -52,6 +52,13 @@ class Section extends Border
*/
private $orientation = self::ORIENTATION_PORTRAIT;
/**
* Paper size
*
* @var \PhpOffice\PhpWord\Style\Paper
*/
private $paper;
/**
* Page Size Width
*
@ -159,6 +166,42 @@ class Section extends Border
*/
private $lineNumbering;
/**
* Create new instance
*/
public function __construct()
{
$this->setPaperSize();
}
/**
* Get paper size
*
* @return string
*/
public function getPaperSize()
{
return $this->paper->getSize();
}
/**
* Set paper size
*
* @param string $value
* @return self
*/
public function setPaperSize($value = 'A4')
{
if ($this->paper === null) {
$this->paper = new Paper();
}
$this->paper->setSize($value);
$this->pageSizeW = $this->paper->getWidth();
$this->pageSizeH = $this->paper->getHeight();
return $this;
}
/**
* Set Setting Value
*

View File

@ -17,8 +17,6 @@
namespace PhpOffice\PhpWord\Writer\RTF\Style;
use PhpOffice\PhpWord\Shared\XMLWriter;
/**
* Border style writer
*

View File

@ -35,13 +35,13 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$oSettings = new Section();
$this->assertEquals('portrait', $oSettings->getOrientation());
$this->assertEquals(11906, $oSettings->getPageSizeW());
$this->assertEquals(16838, $oSettings->getPageSizeH());
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW());
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH());
$oSettings->setSettingValue('orientation', 'landscape');
$this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals(16838, $oSettings->getPageSizeW());
$this->assertEquals(11906, $oSettings->getPageSizeH());
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW());
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH());
$iVal = rand(1, 1000);
$oSettings->setSettingValue('borderSize', $iVal);
@ -106,8 +106,8 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$oSettings->setLandscape();
$this->assertEquals('landscape', $oSettings->getOrientation());
$this->assertEquals(16838, $oSettings->getPageSizeW());
$this->assertEquals(11906, $oSettings->getPageSizeH());
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW());
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH());
}
/**
@ -120,8 +120,8 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
$oSettings->setPortrait();
$this->assertEquals('portrait', $oSettings->getOrientation());
$this->assertEquals(11906, $oSettings->getPageSizeW());
$this->assertEquals(16838, $oSettings->getPageSizeH());
$this->assertEquals(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW());
$this->assertEquals(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH());
}
/**