Example #1
1
function pdf_create($html, $filename = '')
{
    // need to enable magic quotes for the
    $magic_quotes_enabled = get_magic_quotes_runtime();
    if (!$magic_quotes_enabled) {
        ini_set('magic_quotes_runtime', TRUE);
    }
    $dompdf = new Dompdf\Dompdf();
    $dompdf->loadHtml($html);
    $dompdf->render();
    if (!$magic_quotes_enabled) {
        ini_set('magic_quotes_runtime', $magic_quotes_enabled);
    }
    if ($filename != '') {
        $dompdf->stream($filename . '.pdf');
    } else {
        return $dompdf->output();
    }
}
/**
 * Handles the PDF Conversion
 */
function _print_pdf($html)
{
    global $wp_query;
    if (isset($wp_query->query_vars['pdf'])) {
        // convert to PDF
        $title = wp_strip_all_tags(get_the_title());
        $filename = $title . '.pdf';
        $cached = PDF_CACHE_DIRECTORY . $title . '-' . substr(md5(get_the_modified_time()), -6) . '.pdf';
        // check if we need to generate PDF against cache
        if (defined('DISABLE_PDF_CACHE') && DISABLE_PDF_CACHE || isset($_SERVER['HTTP_PRAGMA']) && $_SERVER['HTTP_PRAGMA'] == 'no-cache' || !file_exists($cached)) {
            // we may need more than 30 seconds execution time
            //set_time_limit(60);
            // include the library
            require_once 'vendor/autoload.php';
            // html to pdf conversion
            $dompdf = new Dompdf\Dompdf();
            $dompdf->setPaper(defined('DOMPDF_PAPER_SIZE') ? DOMPDF_PAPER_SIZE : DOMPDF_DEFAULT_PAPER_SIZE, defined('DOMPDF_PAPER_ORIENTATION') ? DOMPDF_PAPER_ORIENTATION : 'portrait');
            $options = $dompdf->getOptions();
            $options->set(array('fontDir' => DOMPDF_FONT_DIR, 'fontCache' => DOMPDF_FONT_CACHE, 'isHtml5ParserEnabled' => DOMPDF_ENABLE_HTML5, 'isRemoteEnabled' => DOMPDF_ENABLE_REMOTE));
            // allow setting a different DPI value
            if (defined('DOMPDF_DPI')) {
                $options->set(array('dpi' => DOMPDF_DPI));
            }
            $dompdf->setOptions($options);
            // allow other plugins to filter the html before passing it to dompdf
            $html = apply_filters('pdf_html_to_dompdf', $html);
            $dompdf->loadHtml($html);
            //$dompdf->setBasePath(get_stylesheet_directory_uri());
            $dompdf->render();
            if (defined('DISABLE_PDF_CACHE') && DISABLE_PDF_CACHE) {
                //just stream the PDF to user if caches are disabled
                return $dompdf->stream($filename, array("Attachment" => false));
            }
            // create PDF cache if one doesn't yet exist
            if (!is_dir(PDF_CACHE_DIRECTORY)) {
                @mkdir(PDF_CACHE_DIRECTORY);
            }
            //save the pdf file to cache
            file_put_contents($cached, $dompdf->output());
        }
        //read and display the cached file
        header('Content-type: application/pdf');
        header('Content-Disposition: inline; filename="' . $filename . '"');
        header('Content-Transfer-Encoding: binary');
        header('Content-Length: ' . filesize($cached));
        header('Accept-Ranges: bytes');
        readfile($cached);
    } else {
        // print the HTML raw
        echo $html;
    }
    // kill php after output is complete
    die;
}
Example #3
0
             if (array_key_exists($language, $extensions)) {
                 $language = $extensions[$language];
             }
             $geshi = new GeSHi(base64_decode($blob['content']), $language);
             $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
             $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);
             $files[$path] = array('filename' => basename($path), 'path' => dirname($path), 'content' => $geshi->parse_code());
         }
         $smarty->assign('files', $files);
         if (empty($_REQUEST['pdf']) || !$_REQUEST['pdf']) {
             $smarty->display('display.tpl');
         } else {
             $dompdf = new \Dompdf\Dompdf();
             $dompdf->loadHtml($smarty->fetch('display.tpl'));
             $dompdf->render();
             $dompdf->stream();
             exit;
         }
         break;
     }
     /* flow into STEP_FILES */
 /* flow into STEP_FILES */
 case STEP_FILES:
     if (empty($_REQUEST['commit_url'])) {
         $smarty->addMessage('Missing Commit URL', 'You must provide the URL of a specific commit to your repository on GitHub for this to work.', NotificationMessage::ERROR);
         $step = STEP_COMMIT;
     }
     if ($step == STEP_FILES) {
         /* get the commit information */
         try {
             $commit = json_decode($github->get(preg_replace('%^https://github.com/(.*)/commit/(.*)$%', 'repos/$1/commits/$2', $_REQUEST['commit_url'])), true);