How to use tcpdf in Codeigniter?


by lottie , in category: PHP Frameworks , 9 months ago

How to use tcpdf in Codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by orpha , 3 months ago


To use TCPDF in Codeigniter, you can follow these steps:

  1. Download and extract the TCPDF library from the official website (
  2. Place the extracted TCPDF folder inside the application/libraries folder of your Codeigniter project.
  3. In your controller, load the TCPDF library using the $this->load->library() method. For example:

  1. Create a new PDF document using the TCPDF() constructor. You can pass the page size, orientation and other parameters as arguments to the constructor. For example:
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);

  1. Set the document properties using the SetTitle(), SetAuthor() and SetSubject() methods. For example:
$pdf->SetTitle('My PDF Document');
$pdf->SetAuthor('John Doe');
$pdf->SetSubject('PDF with TCPDF in Codeigniter');

  1. Add content to the PDF using the various methods provided by TCPDF, such as AddPage(), WriteHTML(), Cell(), Multicell(), etc.
  2. Output the PDF to the browser or save it to a file using the Output() method. For example:
$pdf->Output('my_pdf_document.pdf', 'I');

This will output the PDF to the browser. You can also use the F option to save the PDF to a file on the server.

I hope this helps! Let me know if you have any questions.