CodeIgniter – Plugin for DOMPDF

I have modified the plugin for DOMPDF which is found in CodeIgniter forum. I have added the paper size and orientation parameters. Here is the code to share with you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
 
    function pdf_create($html, $filename, $stream=true, $papersize = 'letter', $orientation = 'portrait')
    {
        require_once("dompdf/dompdf_config.inc.php");
 
        $dompdf = new DOMPDF();
        $dompdf->load_html($html);
        $dompdf->set_paper($papersize, $orientation);
        $dompdf->render();
 
        if ($stream)
        {
            $options['Attachment'] = 1;
            $options['Accept-Ranges'] = 0;
            $options['compress'] = 1;
            $dompdf->stream($filename.".pdf", $options);
        }
        else
        {
            write_file("$filename.pdf", $dompdf->output());
        }
    }
?>
share save 120 16 CodeIgniter   Plugin for DOMPDF

13 thoughts on “CodeIgniter – Plugin for DOMPDF”

  1. Hello,
    I’m using XAMPP too, but I wonder why I can’t run “Hello world” example of DOMpdf, it made my apache crashed many times :’(
    I unzip dompdf-0.5.1.zip to htdocs, then just open a hello_world.php.

    If you have any suggestion please help me

    Thanks a lot

  2. DOMPDF by default uses PDFLib as back-end. If you do not want to use PDFLib then you may read this. The version of PDFLib with XAMPP (last checked with XAMPP 1.6.x) crashes Apache server. To resolve this issue do the following:

    1. Downloaded the latest free version of PDFLib from http://www.pdflib.com.
    2. Put the dll file in your PHP extension directory. (I assume it is C:\Program Files\xampp\php\ext\. To get the location of extension directory you may search in xampp/apache/bin/php.ini file or search in content generated by phpinfo()).
    3. Open xampp/apache/bin/php.ini file and comment this line (put ‘;’ before this line):

    extension=php_pdf.dll;

    And add the following line after this line (Assuming the dll file name is lib_pdf.dll):

    extension=lib_pdf.dll;

    4. Restart Apache server and now see.

    Hope this will solve your problem.

  3. hello,
    I just did one step
    Comment this line “extension=php_pdf.dll;”
    And it works now ! Thanks so much

    btw, do I need to use libpdf_php.dll ? What will be the difference if I don’t use it ?

  4. Yaah! It worked because DOMPDF did not find the PDFLib because of commenting the line. So, it moves for next option to use as back-end.

    If you want to use PDFLib as back-end then you may use the libpdf_php.dll. Else no need :)

  5. Try changing the following line in dompdf_config.inc.php –

    define(“DOMPDF_PDF_BACKEND”, “PDFLib”);

    To:

    define(“DOMPDF_PDF_BACKEND”, “CPDF”);

    It will use the bundled CPDF library.

  6. still not work :’(
    I tried this document, the last word “b?n” becomes “b?n”

    chào các b?n

  7. Nice to see this blog.

    However i also use this dompdf plugin in CI. It’s really very easy. But i faced a problem when i crawl a site and wanted to pdf with that site CSS . But i failed to print that pdf with css.

  8. I also had some problems running PDFLib on xampp and Codeigniter. I updated the dll with the latest version on pdflib.com but it seems it’s not free :) so it displays a big watermark saying “www.pdflib.com”. I tryed to switch DOMPdf backend rendering engine to CPDF but this also crashes my xampp. I’ll go on using PDFLib but do you know how I could get CPDF library to not crash my apache? :)

    Thanks

  9. Hi i follow the script to add papersize and orientation. before that the paper is use portrait and print in 2page. After i add parameter $papersize and $orientation and $dompdf->set_paper($papersize, $orientation); It is sucessfully the paper printed as landscape but just firstpage shown. What the mistakes

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>