GH-5 : Word2007 : Added support for page header & page footer height
This commit is contained in:
parent
5a6cb0891f
commit
d1e16a66d6
|
|
@ -158,6 +158,16 @@ class PHPWord_Section_Settings
|
||||||
*/
|
*/
|
||||||
private $pageNumberingStart;
|
private $pageNumberingStart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $headerHeight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $footerHeight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new Section Settings
|
* Create new Section Settings
|
||||||
*/
|
*/
|
||||||
|
|
@ -178,6 +188,8 @@ class PHPWord_Section_Settings
|
||||||
$this->_borderRightColor = null;
|
$this->_borderRightColor = null;
|
||||||
$this->_borderBottomSize = null;
|
$this->_borderBottomSize = null;
|
||||||
$this->_borderBottomColor = null;
|
$this->_borderBottomColor = null;
|
||||||
|
$this->headerHeight = 720; // set default header and footer to 720 twips (.5 inches)
|
||||||
|
$this->footerHeight = 720;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -568,4 +580,42 @@ class PHPWord_Section_Settings
|
||||||
{
|
{
|
||||||
return $this->pageNumberingStart;
|
return $this->pageNumberingStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Header Height
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getHeaderHeight() {
|
||||||
|
return $this->headerHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Header Height
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setHeaderHeight($pValue = '') {
|
||||||
|
$this->headerHeight = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Footer Height
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getFooterHeight() {
|
||||||
|
return $this->footerHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Footer Height
|
||||||
|
*
|
||||||
|
* @param int $pValue
|
||||||
|
*/
|
||||||
|
public function setFooterHeight($pValue = '') {
|
||||||
|
$this->footerHeight = $pValue;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
|
||||||
$marginRight = $settings->getMarginRight();
|
$marginRight = $settings->getMarginRight();
|
||||||
$marginBottom = $settings->getMarginBottom();
|
$marginBottom = $settings->getMarginBottom();
|
||||||
|
|
||||||
|
$headerHeight = $settings->getHeaderHeight();
|
||||||
|
$footerHeight = $settings->getFooterHeight();
|
||||||
|
|
||||||
$borders = $settings->getBorderSize();
|
$borders = $settings->getBorderSize();
|
||||||
|
|
||||||
$objWriter->startElement('w:sectPr');
|
$objWriter->startElement('w:sectPr');
|
||||||
|
|
@ -175,8 +178,8 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
|
||||||
$objWriter->writeAttribute('w:right', $marginRight);
|
$objWriter->writeAttribute('w:right', $marginRight);
|
||||||
$objWriter->writeAttribute('w:bottom', $marginBottom);
|
$objWriter->writeAttribute('w:bottom', $marginBottom);
|
||||||
$objWriter->writeAttribute('w:left', $marginLeft);
|
$objWriter->writeAttribute('w:left', $marginLeft);
|
||||||
$objWriter->writeAttribute('w:header', '720');
|
$objWriter->writeAttribute('w:header', $headerHeight);
|
||||||
$objWriter->writeAttribute('w:footer', '720');
|
$objWriter->writeAttribute('w:footer', $footerHeight);
|
||||||
$objWriter->writeAttribute('w:gutter', '0');
|
$objWriter->writeAttribute('w:gutter', '0');
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ Changes in branch for release 0.7.1 :
|
||||||
- Feature: (RomanSyroeshko) GH-56 GH-57 - Template : Permit to save a template generated as a file (PHPWord_Template::saveAs())
|
- Feature: (RomanSyroeshko) GH-56 GH-57 - Template : Permit to save a template generated as a file (PHPWord_Template::saveAs())
|
||||||
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
|
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
|
||||||
- Feature: (gabrielbull) - Word2007 : Added support for line height
|
- Feature: (gabrielbull) - Word2007 : Added support for line height
|
||||||
|
- Feature: (JillElaine) GH-5 - Word2007 : Added support for page header & page footer height
|
||||||
- QA: (Progi1984) - UnitTests
|
- QA: (Progi1984) - UnitTests
|
||||||
|
|
||||||
Changes in branch for release 0.7.0 :
|
Changes in branch for release 0.7.0 :
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
|
||||||
|
define('EOL', PHP_EOL);
|
||||||
|
} else {
|
||||||
|
define('EOL', '<br />');
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once '../Classes/PHPWord.php';
|
||||||
|
|
||||||
|
// New Word Document
|
||||||
|
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
|
||||||
|
$PHPWord = new PHPWord();
|
||||||
|
|
||||||
|
// New portrait section
|
||||||
|
$section = $PHPWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
|
||||||
|
$section->addText('I am placed on a default section.');
|
||||||
|
|
||||||
|
// New landscape section
|
||||||
|
$section = $PHPWord->createSection(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->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->addText('This section and we play with header/footer height.');
|
||||||
|
$section->createHeader()->addText('Header');
|
||||||
|
$section->createFooter()->addText('Footer');
|
||||||
|
|
||||||
|
// Save File
|
||||||
|
echo date('H:i:s') , ' Write to Word2007 format' , EOL;
|
||||||
|
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
|
||||||
|
$objWriter->save(str_replace('.php', '.docx', __FILE__));
|
||||||
|
|
||||||
|
/*echo date('H:i:s') , ' Write to OpenDocumentText format' , EOL;
|
||||||
|
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText');
|
||||||
|
$objWriter->save(str_replace('.php', '.odt', __FILE__));
|
||||||
|
|
||||||
|
echo date('H:i:s') , ' Write to RTF format' , EOL;
|
||||||
|
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF');
|
||||||
|
$objWriter->save(str_replace('.php', '.rtf', __FILE__));*/
|
||||||
|
|
||||||
|
|
||||||
|
// Echo memory peak usage
|
||||||
|
echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , ' MB' , EOL;
|
||||||
|
|
||||||
|
// Echo done
|
||||||
|
echo date('H:i:s') , ' Done writing file' , EOL;
|
||||||
Loading…
Reference in New Issue