Dream House

Courage to do something…

CodeIgniter - Plugin for DOMPDF

Posted by Mohammad Sajjad Hossain on June 21st, 2008

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/Bookmark

10 Responses to “CodeIgniter - Plugin for DOMPDF”

  1. Arafat Rahman Says:

    I also working on CodeIgniter. Hope your tips help me. Thanks for the sharing
    Oh ya, Nice design of your site.

    Keep in touch.

  2. Vy Says:

    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

  3. Sajjad Says:

    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.

  4. Vy Says:

    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 ?

  5. Sajjad Says:

    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 :)

  6. Vy Says:

    I have new trouble :( Can’t create files with font Unicode, they asked for licensed PDFLib :(

  7. Sajjad Says:

    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.

  8. Vy Says:

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

    chào các b?n

  9. bijon Says:

    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.

  10. Mohammad Sajjad Hossain Says:

    Thanks Bijon :).

    I haven’t tried that yet. When I will do that I will definitely let others know through this site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">