/** * @param $outDocxFilePath * @param bool $addPageBreak * @return bool * @throws \Exception */ public function save($outDocxFilePath, $addPageBreak = false) { if (!count($this->files)) { // No files to merge return false; } if (!copy($this->files[0], $outDocxFilePath)) { // Cannot create file throw new \Exception("error saving output file {$outDocxFilePath}"); } $docx = new DocxLib\Docx($outDocxFilePath); for ($i = 1; $i < count($this->files); $i++) { $docx->addFile($this->files[$i], "part" . $i . ".docx", "rId10" . $i, $addPageBreak); } $docx->flush(); return true; }
/** * @param null $outputFilePath * @return bool * @throws \Exception */ public function save($outputFilePath = null) { if (!file_exists($this->templateFilePath)) { throw new \Exception("template file {$this->templateFilePath} not found"); } if ($outputFilePath === null) { $outputFilePath = $this->templateFilePath; } elseif (!copy($this->templateFilePath, $outputFilePath)) { throw new \Exception("error creating output file {$outputFilePath}"); } $docx = new DocxLib\Docx($outputFilePath); $docx->loadHeadersAndFooters(); foreach ($this->data as $key => $value) { $docx->findAndReplace($key, $value); } $docx->flush(); return true; }