diff --git a/Classes/PHPWord/Section/Settings.php b/Classes/PHPWord/Section/Settings.php index 020a82e3..fce8d7b1 100755 --- a/Classes/PHPWord/Section/Settings.php +++ b/Classes/PHPWord/Section/Settings.php @@ -158,6 +158,16 @@ class PHPWord_Section_Settings */ private $pageNumberingStart; + /** + * @var int + */ + private $headerHeight; + + /** + * @var int + */ + private $footerHeight; + /** * Create new Section Settings */ @@ -178,6 +188,8 @@ class PHPWord_Section_Settings $this->_borderRightColor = null; $this->_borderBottomSize = 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; } + + /** + * 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; + } } diff --git a/Classes/PHPWord/Writer/Word2007/Document.php b/Classes/PHPWord/Writer/Word2007/Document.php index 41718f6e..8722e53b 100755 --- a/Classes/PHPWord/Writer/Word2007/Document.php +++ b/Classes/PHPWord/Writer/Word2007/Document.php @@ -135,6 +135,9 @@ class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base $marginRight = $settings->getMarginRight(); $marginBottom = $settings->getMarginBottom(); + $headerHeight = $settings->getHeaderHeight(); + $footerHeight = $settings->getFooterHeight(); + $borders = $settings->getBorderSize(); $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:bottom', $marginBottom); $objWriter->writeAttribute('w:left', $marginLeft); - $objWriter->writeAttribute('w:header', '720'); - $objWriter->writeAttribute('w:footer', '720'); + $objWriter->writeAttribute('w:header', $headerHeight); + $objWriter->writeAttribute('w:footer', $footerHeight); $objWriter->writeAttribute('w:gutter', '0'); $objWriter->endElement(); diff --git a/changelog.txt b/changelog.txt index 7b5375b4..bf07c48a 100755 --- a/changelog.txt +++ b/changelog.txt @@ -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: (gabrielbull) - Word2007 : Support sections page numbering - Feature: (gabrielbull) - Word2007 : Added support for line height +- Feature: (JillElaine) GH-5 - Word2007 : Added support for page header & page footer height - QA: (Progi1984) - UnitTests Changes in branch for release 0.7.0 : diff --git a/samples/Sample_03_Sections.php b/samples/Sample_03_Sections.php new file mode 100755 index 00000000..d2231dfa --- /dev/null +++ b/samples/Sample_03_Sections.php @@ -0,0 +1,55 @@ +'); +} + +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;