Pressbooks\Modules\Export\Prince\Pdf::convert PHP Method

convert() public method

Create $this->outputPath
public convert ( ) : boolean
return boolean
    function convert()
    {
        // Sanity check
        if (empty($this->exportStylePath) || !is_file($this->exportStylePath)) {
            $this->logError('$this->exportStylePath must be set before calling convert().');
            return false;
        }
        // Set logfile
        $this->logfile = $this->createTmpFile();
        // Set filename
        $filename = $this->timestampedFileName('.pdf');
        $this->outputPath = $filename;
        // Fonts
        Container::get('GlobalTypography')->getFonts();
        // CSS File
        $css = $this->kneadCss();
        $css_file = $this->createTmpFile();
        file_put_contents($css_file, $css);
        // Save PDF as file in exports folder
        $prince = new \PrinceXMLPhp\PrinceWrapper(PB_PRINCE_COMMAND);
        $prince->setHTML(true);
        $prince->setCompress(true);
        if (defined('WP_ENV') && WP_ENV == 'development') {
            $prince->setInsecure(true);
        }
        if ($this->pdfProfile && $this->pdfOutputIntent) {
            $prince->setOptions('--pdf-profile=' . $this->pdfProfile . ' --pdf-output-intent=' . $this->pdfOutputIntent);
        }
        $prince->addStyleSheet($css_file);
        if ($this->exportScriptPath) {
            $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;
    }