public static getWeb2PrintConfig ( ) : Zend_Config | ||
Résultat | Zend_Config |
/** * @return PdfReactor8|WkHtmlToPdf * @throws \Exception */ public static function getInstance() { $config = Config::getWeb2PrintConfig(); if ($config->generalTool == "pdfreactor") { return new PdfReactor8(); } elseif ($config->generalTool == "wkhtmltopdf") { return new WkHtmlToPdf(); } else { throw new \Exception("Invalid Configuation - " . $config->generalTool); } }
public function getProcessingOptions() { include_once 'Pimcore/Web2Print/Processor/api/v' . Config::getWeb2PrintConfig()->get('pdfreactorVersion', '8.0') . '/PDFreactor.class.php'; $options = []; $options[] = ["name" => "author", "type" => "text", "default" => ""]; $options[] = ["name" => "title", "type" => "text", "default" => ""]; $options[] = ["name" => "printermarks", "type" => "bool", "default" => ""]; $options[] = ["name" => "links", "type" => "bool", "default" => true]; $options[] = ["name" => "bookmarks", "type" => "bool", "default" => true]; $options[] = ["name" => "tags", "type" => "bool", "default" => true]; $options[] = ["name" => "javaScriptMode", "type" => "select", "values" => [\JavaScriptMode::ENABLED, \JavaScriptMode::DISABLED, \JavaScriptMode::ENABLED_NO_LAYOUT], "default" => \JavaScriptMode::ENABLED]; $options[] = ["name" => "viewerPreference", "type" => "select", "values" => [\ViewerPreferences::PAGE_LAYOUT_SINGLE_PAGE, \ViewerPreferences::PAGE_LAYOUT_TWO_COLUMN_LEFT, \ViewerPreferences::PAGE_LAYOUT_TWO_COLUMN_RIGHT], "default" => \ViewerPreferences::PAGE_LAYOUT_SINGLE_PAGE]; $options[] = ["name" => "colorspace", "type" => "select", "values" => [\ColorSpace::CMYK, \ColorSpace::RGB], "default" => \ColorSpace::CMYK]; $options[] = ["name" => "encryption", "type" => "select", "values" => [\Encryption::NONE, \Encryption::TYPE_40, \Encryption::TYPE_128], "default" => \Encryption::NONE]; $options[] = ["name" => "loglevel", "type" => "select", "values" => [\LogLevel::FATAL, \LogLevel::WARN, \LogLevel::INFO, \LogLevel::DEBUG, \LogLevel::PERFORMANCE], "default" => \LogLevel::FATAL]; return $options; }
public function saveAction() { if ($this->getParam("id")) { $page = Document\Printpage::getById($this->getParam("id")); $page = $this->getLatestVersion($page); $page->setUserModification($this->getUser()->getId()); // save to session $key = "document_" . $this->getParam("id"); $session = new \Zend_Session_Namespace("pimcore_documents"); $session->{$key} = $page; if ($this->getParam("task") == "unpublish") { $page->setPublished(false); } if ($this->getParam("task") == "publish") { $page->setPublished(true); } // only save when publish or unpublish if ($this->getParam("task") == "publish" && $page->isAllowed("publish") or $this->getParam("task") == "unpublish" && $page->isAllowed("unpublish")) { //check, if to cleanup existing elements of document $config = Config::getWeb2PrintConfig(); if ($config->generalDocumentSaveMode == "cleanup") { $page->setElements([]); } $this->setValuesToDocument($page); try { $page->save(); $this->_helper->json(["success" => true]); } catch (\Exception $e) { Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } else { if ($page->isAllowed("save")) { $this->setValuesToDocument($page); try { $page->saveVersion(); $this->_helper->json(["success" => true]); } catch (\Exception $e) { Logger::err($e); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } $this->_helper->json(false); }
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 . DIRECTORY_SEPARATOR . "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/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; }
public function getWeb2printAction() { $this->checkPermission("web2print_settings"); $values = Config::getWeb2PrintConfig(); $valueArray = $values->toArray(); $optionsString = []; if ($valueArray['wkhtml2pdfOptions']) { foreach ($valueArray['wkhtml2pdfOptions'] as $key => $value) { $tmpStr = "--" . $key; if ($value !== null && $value !== "") { $tmpStr .= " " . $value; } $optionsString[] = $tmpStr; } } $valueArray['wkhtml2pdfOptions'] = implode("\n", $optionsString); $response = ["values" => $valueArray]; $this->_helper->json($response); }
public static function getTempFileUrl() { $web2printConfig = Config::getWeb2PrintConfig(); if ($web2printConfig->wkhtml2pdfHostname) { return $web2printConfig->wkhtml2pdfHostname . "/website/var/tmp/"; } elseif (\Pimcore\Config::getSystemConfig()->general->domain) { $hostname = \Pimcore\Config::getSystemConfig()->general->domain; } else { $hostname = $_SERVER["HTTP_HOST"]; } $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'; return $protocol . "://" . $hostname . "/website/var/tmp/"; }