Example #1
5
 /**
  * @inheritdoc
  */
 protected function convertInternal($html, $outputFileName, $options)
 {
     $pageSize = ArrayHelper::remove($options, 'pageSize', 'A4');
     $orientation = ArrayHelper::remove($options, 'orientation', 'portrait');
     if (empty($options)) {
         $dompdfOptions = null;
     } else {
         $dompdfOptions = new \Dompdf\Options();
         foreach ($options as $name => $value) {
             $dompdfOptions->set($name, $value);
         }
     }
     $dompdf = new \Dompdf\Dompdf($dompdfOptions);
     $dompdf->setPaper($pageSize, $orientation);
     $dompdf->loadHtml($html);
     $dompdf->render();
     file_put_contents($outputFileName, $dompdf->output());
 }
Example #2
4
 public function __invoke(Request $req, Response $res)
 {
     $school = $req->getAttribute('school');
     $appForm = $this->appFormService->findSchoolApplicationForm($school->id);
     if (null === $appForm) {
         return $res->withStatus(404);
     }
     $html = $this->view->fetch('application_form/pdf.twig', ['school' => $school, 'appForm' => $appForm, 'logo' => base64_encode(file_get_contents(__DIR__ . '/../../public/img/application_form/minedu_logo.jpg')), 'style' => file_get_contents(__DIR__ . '/../../public/css/application_form/pdf.css')]);
     $pdf = new \Dompdf\Dompdf(['default_paper_size' => 'A4', 'default_font' => 'DejaVu Sans', 'isHtml5ParserEnabled' => true, 'is_remote_enabled' => false]);
     $pdf->loadHtml($html);
     $pdf->render();
     $filename = 'edulabs_app_form_' . $appForm['id'] . '.pdf';
     $str = $pdf->output();
     $length = mb_strlen($str, '8bit');
     return $res->withHeader('Cache-Control', 'private')->withHeader('Content-type', 'application/pdf')->withHeader('Content-Length', $length)->withHeader('Content-Disposition', 'attachment;  filename=' . $filename)->withHeader('Accept-Ranges', $length)->write($str);
 }
Example #3
3
 /**
  * Format a recordset
  *
  * @param Garp_Model $model
  * @param array $rowset
  * @return string
  */
 public function format(Garp_Model $model, array $rowset)
 {
     $html = parent::format($model, $rowset);
     $dompdf = new Dompdf\Dompdf();
     $dompdf->load_html($html);
     $dompdf->set_paper('a4', 'portrait');
     $dompdf->render();
     $out = $dompdf->output();
     return $out;
 }
Example #4
3
 public function print_render($template, $data = array(), $paper = array("A4", "portrait"))
 {
     $dompdf = new \Dompdf\Dompdf();
     $options = new \Dompdf\Options();
     // set options indvidiually
     $options->set('isPhpEnabled', true);
     $dompdf->setOptions($options);
     $dompdf->set_paper($paper[0], $paper[1]);
     $this->html_render($template);
     $html = $this->view->render($template . EXT, $data);
     $dompdf->load_html($html);
     $dompdf->render();
     return $dompdf;
 }
Example #5
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 #7
0
         foreach ($_REQUEST['files'] as $path => $url) {
             $blob = json_decode($github->get($url), true);
             $language = preg_replace('/^.*\\.(\\w+)$/', '$1', $path);
             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) {