diff --git a/src/PhpWord/Writer/RTF/Part/Document.php b/src/PhpWord/Writer/RTF/Part/Document.php index d4bfadb4c5..66dd8fd14d 100644 --- a/src/PhpWord/Writer/RTF/Part/Document.php +++ b/src/PhpWord/Writer/RTF/Part/Document.php @@ -121,10 +121,26 @@ private function writeSections() $sections = $this->getParentWriter()->getPhpWord()->getSections(); foreach ($sections as $section) { + // Write styles $styleWriter = new SectionStyleWriter($section->getStyle()); $styleWriter->setParentWriter($this->getParentWriter()); $content .= $styleWriter->write(); + // Append headers / footers + $sectionParts = array('Header', 'Footer'); + foreach ($sectionParts as $sectionPart) { + $getFunction = 'get' . $sectionPart . 's'; + $className = 'PhpOffice\\PhpWord\\Writer\\RTF\\Part\\Section' . $sectionPart; + $parts = $section->$getFunction(); + foreach ($parts as $part) { + $partWriter = new $className(); + $partWriter->setParentWriter($this->getParentWriter()); + $partWriter->setElement($part); + $content .= $partWriter->write(); + } + } + + // Write content $elementWriter = new Container($this->getParentWriter(), $section); $content .= $elementWriter->write(); diff --git a/src/PhpWord/Writer/RTF/Part/SectionFooter.php b/src/PhpWord/Writer/RTF/Part/SectionFooter.php new file mode 100644 index 0000000000..12b0ae1502 --- /dev/null +++ b/src/PhpWord/Writer/RTF/Part/SectionFooter.php @@ -0,0 +1,78 @@ +rootElement; + $type = $this->element->getType(); + if ($type == Footer::FIRST) { + $content .= 'f'; + } elseif ($type == Footer::EVEN) { + $content .= 'r'; + } + + $containerWriter = new Container($this->getParentWriter(), $this->element); + $content .= $containerWriter->write(); + + $content .= '}' . PHP_EOL; + + return $content; + } + + /** + * Set element + * + * @param \PhpOffice\PhpWord\Element\Footer|\PhpOffice\PhpWord\Element\Header $element + * @return self + */ + public function setElement($element) + { + $this->element = $element; + + return $this; + } +} diff --git a/src/PhpWord/Writer/RTF/Part/SectionHeader.php b/src/PhpWord/Writer/RTF/Part/SectionHeader.php new file mode 100644 index 0000000000..c6b8f19d87 --- /dev/null +++ b/src/PhpWord/Writer/RTF/Part/SectionHeader.php @@ -0,0 +1,31 @@ +