Inheritance: extends PageSnippet
Exemple #1
0
 public function pdfIsDirty()
 {
     $dirty = parent::pdfIsDirty();
     if (!$dirty) {
         $dirty = $this->getLastGenerated() < $this->getLastedChildModificationDate();
     }
     return $dirty;
 }
Exemple #2
0
 protected function buildPdf(Document\PrintAbstract $document, $config)
 {
     $web2PrintConfig = Config::getWeb2PrintConfig();
     $params = [];
     $params['printermarks'] = $config->printermarks == "true";
     $params['screenResolutionImages'] = $config->screenResolutionImages == "true";
     $this->updateStatus($document->getId(), 10, "start_html_rendering");
     $html = $document->renderDocument($params);
     $this->updateStatus($document->getId(), 40, "finished_html_rendering");
     $filePath = PIMCORE_TEMPORARY_DIRECTORY . "/pdf-reactor-input-" . $document->getId() . ".html";
     file_put_contents($filePath, $html);
     $html = null;
     $this->updateStatus($document->getId(), 45, "saved_html_file");
     ini_set("default_socket_timeout", 3000);
     ini_set('max_input_time', -1);
     include_once 'Pimcore/Web2Print/Processor/api/v' . $web2PrintConfig->get('pdfreactorVersion', '8.0') . '/PDFreactor.class.php';
     $port = (string) $web2PrintConfig->pdfreactorServerPort ? (string) $web2PrintConfig->pdfreactorServerPort : "9423";
     $pdfreactor = new \PDFreactor("http://" . $web2PrintConfig->pdfreactorServer . ":" . $port . "/service/rest");
     $filePath = str_replace(PIMCORE_DOCUMENT_ROOT, "", $filePath);
     $reactorConfig = ["document" => (string) $web2PrintConfig->pdfreactorBaseUrl . $filePath, "baseURL" => (string) $web2PrintConfig->pdfreactorBaseUrl, "author" => $config->author ? $config->author : "", "title" => $config->title ? $config->title : "", "addLinks" => $config->links == "true", "addBookmarks" => $config->bookmarks == "true", "javaScriptMode" => $config->javaScriptMode, "viewerPreferences" => [$config->viewerPreference], "defaultColorSpace" => $config->colorspace, "encryption" => $config->encryption, "addTags" => $config->tags == "true", "logLevel" => $config->loglevel];
     if (trim($web2PrintConfig->pdfreactorLicence)) {
         $reactorConfig["licenseKey"] = trim($web2PrintConfig->pdfreactorLicence);
     }
     try {
         $progress = new \stdClass();
         $progress->finished = false;
         $processId = $pdfreactor->convertAsync($reactorConfig);
         while (!$progress->finished) {
             $progress = $pdfreactor->getProgress($processId);
             $this->updateStatus($document->getId(), 50 + $progress->progress / 2, "pdf_conversion");
             Logger::info("PDF converting progress: " . $progress->progress . "%");
             sleep(2);
         }
         $this->updateStatus($document->getId(), 100, "saving_pdf_document");
         $result = $pdfreactor->getDocument($processId);
         $pdf = base64_decode($result->document);
     } catch (\Exception $e) {
         Logger::error($e);
         $document->setLastGenerateMessage($e->getMessage());
         throw new \Exception("Error during REST-Request:" . $e->getMessage());
     }
     $document->setLastGenerateMessage("");
     return $pdf;
 }
Exemple #3
0
 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;
 }
Exemple #4
0
 public function checkPdfDirtyAction()
 {
     $printDocument = Document\PrintAbstract::getById($this->getParam("id"));
     $dirty = true;
     if ($printDocument) {
         $dirty = $printDocument->pdfIsDirty();
     }
     $this->_helper->json(["pdfDirty" => $dirty]);
 }