0

I have downloaded dompdf libraries from github https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf

Controller function

   function pdf()
   {
   $this->load->helper('dompdf');
   // page info here, db calls, etc.     
   $this->data['query'] = $this->my_model->dashboard_db();
   $this->data['queryCmt'] = $this->my_model->dashboard_comment_task_db();
   $html = $this->load->view('home',$this->data, true); 
   $fn = 'file_pdf';
   $data = pdf_create($html, $fn, true);
   write_file($fn, $data);
   //if you want to write it to disk and/or send it as an attachment    
   }

Dom pdf Helper function

   <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
   function pdf_create($html, $filename, $stream=TRUE) 
   {
   require_once("dompdf/dompdf_config.inc.php");

   $dompdf = new DOMPDF();
   $dompdf->load_html($html);
   $dompdf->render();
   if ($stream) {
   $dompdf->stream($filename.".pdf");
   } else {
    return $dompdf->output();
   }
   }
   ?> 

This gives me a server error, but if i remove a pdf_create() in controller in generate one pdf file. Can anyone help one this

Serma
  • 44
  • 1
  • 2
  • 11
  • What exactly is the server error you are getting? – Aram Boyajyan Oct 30 '13 at 11:37
  • It something like, "It may be down for maintenance or configured incorrectly". – Serma Oct 30 '13 at 11:39
  • Check out the server error logs - they should tell you what is the issue exactly. – Aram Boyajyan Oct 30 '13 at 11:44
  • Not stored anything like that – Serma Oct 30 '13 at 12:12
  • Where did you get dompdf? If downloading from github make sure to click on "releases." We recommend [v0.6.0](https://github.com/dompdf/dompdf/releases/tag/v0.6.0-b3). If you click "Download ZIP" from the main page you'll be [missing the required php-font-lib](http://stackoverflow.com/questions/13431905/php-font-lib-must-either-be-installed-via-composer-or-copied-to-lib-php-font-lib). Beyond that, it would help to know what's going on by seeing the error causing that message. Try setting `error_reporting(E_ALL)` in index.php. – BrianS Oct 30 '13 at 13:45
  • no not working in codeigniter, it seems like helper function problem – Serma Oct 31 '13 at 05:31
  • If you have compress_output set to true then add die; $dompdf->stream($filename.".pdf");die; return $dompdf->output(); die; – suncoastkid Oct 31 '13 at 12:27
  • @suncoastkid In pdf_create(), if i use `die;` before `require_once("dompdf/dompdf_config.inc.php")` i will get a blank page but if i use after require_once it shows server error – Serma Nov 01 '13 at 04:51

1 Answers1

0

In your home.php (view) file,

Remove <thead> and <tbody> tags and remove space between <html><head> , </head><body> and </body></html>

It will works fine.!

Amit Nadiyapara
  • 246
  • 2
  • 6