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

13 Comments

  • By Arafat Rahman, June 22, 2008 @ 2:30 pm

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

    Keep in touch.

  • By Vy, June 23, 2008 @ 7:18 pm

    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

  • By Sajjad, June 23, 2008 @ 10:21 pm

    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.

  • By Vy, June 24, 2008 @ 9:13 am

    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 ?

  • By Sajjad, June 24, 2008 @ 5:38 pm

    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 🙂

  • By Vy, June 26, 2008 @ 7:21 am

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

  • By Sajjad, June 26, 2008 @ 5:13 pm

    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.

  • By Vy, June 27, 2008 @ 6:58 am

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

    chào các b?n

  • By bijon, July 6, 2008 @ 1:50 pm

    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.

  • By Mohammad Sajjad Hossain, July 8, 2008 @ 10:20 pm

    Thanks Bijon :).

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

  • By Dabu, March 17, 2009 @ 5:24 am

    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

  • By mello.capinpin, February 16, 2010 @ 1:45 pm

    Commenting “extension=lib_pdf.dll” on php.ini did the trick.

    Thanks

  • By muslih, April 12, 2012 @ 4:00 pm

    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

Other Links to this Post

RSS feed for comments on this post.

Leave a comment

blog