Example #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_file = $this->createTmpFile();
     file_put_contents($css_file, $this->kneadCss());
     // CSS Overrides
     $css_overrides = $this->createTmpFile();
     file_put_contents($css_overrides, $this->cssOverrides);
     // Save PDF as file in exports folder
     $prince = new \Prince(PB_PRINCE_COMMAND);
     $prince->setHTML(true);
     $prince->setCompress(true);
     $prince->addStyleSheet($css_file);
     $prince->addStylesheet($css_overrides);
     $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;
 }