protected function buildPdf(Document\PrintAbstract $document, $config) { $web2printConfig = Config::getWeb2PrintConfig(); $params = []; $this->updateStatus($document->getId(), 10, "start_html_rendering"); $html = $document->renderDocument($params); $placeholder = new \Pimcore\Placeholder(); $html = $placeholder->replacePlaceholders($html); $html = \Pimcore\Helper\Mail::setAbsolutePaths($html, $document, $web2printConfig->wkhtml2pdfHostname); $this->updateStatus($document->getId(), 40, "finished_html_rendering"); file_put_contents(PIMCORE_TEMPORARY_DIRECTORY . DIRECTORY_SEPARATOR . "wkhtmltorpdf-input.html", $html); $this->updateStatus($document->getId(), 45, "saved_html_file"); try { $this->updateStatus($document->getId(), 50, "pdf_conversion"); $pdf = $this->fromStringToStream($html); $this->updateStatus($document->getId(), 100, "saving_pdf_document"); } catch (\Exception $e) { Logger::error($e); $document->setLastGenerateMessage($e->getMessage()); throw new \Exception("Error during REST-Request:" . $e->getMessage()); } $document->setLastGenerateMessage(""); return $pdf; }
/** * Replaces the placeholders with the content and returns the rendered Html * * @return string|null */ public function getBodyHtmlRendered() { $html = $this->getBodyHtml(); //if the content was manually set with $obj->setBodyHtml(); this content will be used //and not the content of the Document! if ($html instanceof \Zend_Mime_Part) { $rawHtml = $html->getRawContent(); $content = $this->placeholderObject->replacePlaceholders($rawHtml, $this->getParams(), $this->getDocument(), $this->getEnableLayoutOnPlaceholderRendering()); } elseif ($this->getDocument() instanceof Model\Document) { $content = $this->placeholderObject->replacePlaceholders($this->getDocument(), $this->getParams(), $this->getDocument(), $this->getEnableLayoutOnPlaceholderRendering()); } else { $content = null; } //modifying the content e.g set absolute urls... if ($content) { $content = MailHelper::embedAndModifyCss($content, $this->getDocument()); $content = MailHelper::setAbsolutePaths($content, $this->getDocument(), $this->getHostUrl()); } return $content; }