Category: DOMPDF

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

DOMPDF without PDFLib as back-end PDF support

dompdf_logoI was implementing PDF generation in one of projects which is built with CodeIgniter. I searched for PDF support for CodeIgniter and found help on CI forum. I followed the instruction given there and used DOMPDF. The result was satisfactory though I faced an issue. I was happy, but the problem was with the PDFLib. Its not free and our client would not buy it. I thought that DOMPDF will not work without the help of PDFLib. Soon I loss my happiness and started looking for an alternate solution. Then our team decided to use HTML2FPDF. But the result was not satisfactory. We had to rewrite our html files. It was lacking lots of HTML support. I was not happy with the output. So I started googling again for a PDF library. While searching I came accross a library called HTML2PS/HTML2PDF. But, it seemed to me complex. I again started searching for any solution which will help me use DOMPDF in my project without PDFLib. At last I got the solution from DOMPDF site ;).

“…Edit dompdf_config.inc.php to fit your installation. If you leave the DOMPDF_PDF_BACKEND setting at ‘auto’ dompdf will use PDFLib if it is installed, otherwise it will use the bundled R&OS CPDF class…”

I was very much happy to read this. I might have missed this while installing DOMPDF for the first time. Thanks DOMPDF for a nice interface and output. Really DOMPDF made our coding not just easy, but saved our times :).

Share

DOMPDF Attachment issue in IE (Internet Explorer)

dompdf_ieI have used DOMPDF in my project. But I was facing problem with Attachment. In FireFox it was working fine. But in Internet Explorer (I used IE 6) it ended with an error. In IE it was showing the download dialogue box offering the script page I used to generate the PDF file. When I tried to download the file it showed an error.

I searched the web and found no suitable solution. I followed the instruction given in http://www.corenettech.com/blog/ but it didn’t work :(. But I got an idea from this post. I started digging the code and have done following changes to PDFLib_Adapter class (available in DOMPDF_DiRECTORY/include/pdflib_adapter.cls.php).

I have removed the following line (line 829):

header("Cache-Control: private");

and added

if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
{
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header("Content-Transfer-Encoding: binary");
     header('Pragma: public');
     header("Content-Length: ".strlen($data));
}
else
{
     header("Cache-Control: private");
     header("Content-Transfer-Encoding: binary");
     header('Expires: 0');
     header('Pragma: no-cache');
     header("Content-Length: ".strlen($data));
}

After

header("Content-type: application/pdf");
header("Content-Disposition: $attach; filename=\"$filename\"");

That’s it! My code started working :).

Hope this will save your time of surfing the net ;).

Share
blog