diff --git a/src/PhpWord/TemplateProcessor.php b/src/PhpWord/TemplateProcessor.php index 269b25e95e..82bec60246 100644 --- a/src/PhpWord/TemplateProcessor.php +++ b/src/PhpWord/TemplateProcessor.php @@ -62,6 +62,13 @@ class TemplateProcessor */ protected $tempDocumentFooters = array(); + /** + * Content of body (in XML format) of the temporary document + * + * @var string[] + */ + protected $tempDocumentBody; + /** * @since 0.12.0 Throws CreateTemporaryFileException and CopyFileException instead of Exception * @@ -101,6 +108,9 @@ public function __construct($documentTemplate) $index++; } $this->tempDocumentMainPart = $this->fixBrokenMacros($this->zipClass->getFromName($this->getMainPartName())); + + // Document body extraction + $this->tempDocumentBody = preg_replace('/.*(.*)<\/w:body>.*/s', '$1', $this->tempDocumentMainPart); } /** @@ -192,6 +202,8 @@ protected static function ensureMacroCompleted($macro) */ protected static function ensureUtf8Encoded($subject) { + $subject = str_replace('&', '&', $subject); + if (!Text::isUTF8($subject)) { $subject = utf8_encode($subject); } @@ -572,4 +584,11 @@ protected function getSlice($startPosition, $endPosition = 0) return substr($this->tempDocumentMainPart, $startPosition, ($endPosition - $startPosition)); } + + /** + * Add new page. + */ + public function addPage() { + $this->tempDocumentMainPart = preg_replace('/<\/w:body>/', ''.$this->tempDocumentBody.'/', $this->tempDocumentMainPart); + } }