0

I'd like to have a page be exported as PDF in codeIgniter. I managed to install the TCPDF library following the instructions from: TCPDF Integration and now my controller looks like:

class Mycontroller extends CI_Controller {

    public function __construct(){

            parent::__construct();
            $this->load->library("Pdf");
    }

    //make pdf
    public function pdf(){

        $pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
        $pdf->SetCreator(PDF_CREATOR);
        // Add a page
        $pdf->AddPage();
        $html = "<h1>Test Page</h1>";
        $pdf->writeHTML($html, true, false, true, false, '');
        $pdf->Output('output.pdf', 'I');
    }
}

Then, I have a link in another page as:

<td><a href="<?php echo base_url(); ?>index.php/myController/pdf">Export As Pdf</a></td>

and when I click on it, I get a blank pdf. The contents of the page are not there.

Any help is greatly appreciated. Thank you!

Marek Skiba
  • 1,846
  • 1
  • 20
  • 27
moijoune
  • 21
  • 8
  • 1
    Blank page means not reported error. You should [turn error reporting on](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) to see the exact error. – Zoli Szabó Sep 11 '16 at 08:45
  • 1
    Note: you have named your class wrong http://www.codeigniter.com/user_guide/general/styleguide.html#file-naming – Mr. ED Sep 11 '16 at 09:20
  • You are right! I just edited code according to your suggestion! Thank you very much!!!!!!!!!!!! – moijoune Sep 11 '16 at 09:32
  • 1
    @moijoune should be some thing like Mycontroller only first letter upper case on class and file name – Mr. ED Sep 11 '16 at 09:50
  • I'll edit it again :) thank you! – moijoune Sep 11 '16 at 10:10

0 Answers0