Пример #1
0
 /**
  * Create $this->outputPath
  *
  * @return bool
  */
 function convert()
 {
     // Sanity check
     if (empty($this->exportStylePath) || !is_file($this->exportStylePath)) {
         $this->logError('$this->exportStylePath must be set before calling convert().');
         return false;
     }
     // Convert
     require_once PB_PLUGIN_DIR . 'symbionts/prince/prince.php';
     // Set logfile
     $this->logfile = $this->createTmpFile();
     // Set filename
     $filename = $this->timestampedFileName('.pdf');
     $this->outputPath = $filename;
     // CSS File
     $css = $this->kneadCss();
     $css_file = $this->createTmpFile();
     file_put_contents($css_file, $css);
     // Save PDF as file in exports folder
     $prince = new \Prince(PB_PRINCE_COMMAND);
     $prince->setHTML(true);
     $prince->setCompress(true);
     $prince->addStyleSheet($css_file);
     $prince->addScript($this->exportScriptPath);
     $prince->setLog($this->logfile);
     $retval = $prince->convert_file_to_file($this->url, $this->outputPath, $msg);
     // Prince XML is very flexible. There could be errors but Prince will still render a PDF.
     // We want to log those errors but we won't alert the user.
     if (count($msg)) {
         $this->logError(file_get_contents($this->logfile));
     }
     return $retval;
 }
Пример #2
0
 if ($row['type'] == 'toc') {
     $title = $row['content'];
     if ($title == '') {
         $title = 'Inhaltsverzeichnis';
     }
     $book_contents .= "        - { element: toc, title: {$title}  }\n";
 }
 if ($row['type'] == 'cover') {
     $img = $row['content'];
     if ($img != "" && is_file(CO_PATH . '/books/' . $book_owner . '/uploads/' . $img)) {
         copy(CO_PATH . '/books/' . $book_owner . '/uploads/' . $img, $book_dir . '/Resources/Templates/ebook/cover.jpg');
         copy(CO_PATH . '/books/' . $book_owner . '/uploads/' . $img, $book_dir . '/Resources/Templates/kindle/cover.jpg');
         // then convert to pdf
         include '../includes/prince.php';
         $prince = new Prince('/usr/bin/prince');
         $prince->setHTML(1);
         $prince->addStyleSheet(CO_PATH . '/default_styles.css');
         $prince->setLog(CO_PATH . "/log.txt");
         $xmlPath = $book_dir . '/Resources/Templates/ebook/cover.html';
         $pdfPath = $book_dir . '/Resources/Templates/print/cover.pdf';
         $prince->convert_file_to_file($xmlPath, $pdfPath);
         /*$errorMessages = array();
         		if($prince->convert_file_to_file($xmlPath, $pdfPath, $errorMessages)) {
         			echo "true";
         		} else {
         			echo 'false';
         		}
         		print_r($errorMessages);*/
     }
     $book_contents .= "        - { element: cover }\n";
 }