CodeIgniter 3 PDF Generate Tutorial With Example

Today, We want to share with you CodeIgniter 3 PDF Generate Tutorial With Example.In this post we will show you Generate and Download PDF in Codeigniter using mPDF, hear for Codeigniter 3 – Generate PDF from view using dompdf library with example we will give you demo and example for implement.In this post, we will learn about CodeIgniter 3 Tutorial PDF For Beginners with an example.

CodeIgniter 3 PDF Generate Tutorial With Example

There are the Following The simple About CodeIgniter 3 PDF Generate Tutorial With Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Generate PDF Report from MySQL Database using Codeigniter 3, so the How to Generate and Download PDF in Codeigniter using mPDF for this example is following below.

Step 1 : install CodeIgniter 3 Application

Download and Setup CodeIgniter 3 Project.

Step 2 : Setup mPDF Library in CodeIgniter 3

And then Run below simple composer command on terminal to download main vendor folder to put mPDF library from your CodeIgniter 3 project folder. run this command Into make a new simple folder like name as a “vendor” as well as it will download composer To “mpdf” library into it.

$ composer require mpdf/mpdf

Setp 3 : set CodeIgniter vendor Folder path


 $config['composer_autoload'] = 'vendor/autoload.php';

Step 4 : Create a Call mPDF Library in CodeIgniter Controller


load->view('html_to_pdf',[],true); //CodeIgniter view file name
        $live_mpdf->Output(); // simple run and opens in browser
        //$live_mpdf->Output('pakainfo_details.pdf','D'); // it CodeIgniter downloads the file into the main dynamic system, with give your file name

Step 5 : Create a CodeIgniter View Files

view / html_to_pdf.php

    Welcome to


Welcome to!

Pakainfo is the most popular Programming & Web Development blog.

Our mission is to provide the best online resources on programming and web development.

We deliver the useful and best tutorials for web professionals — developers, programmers, freelancers and site owners.

Any visitors of this site are free to browse our tutorials, live demos and download scripts.

Click here to More Information for

Generate and Download PDF file in Codeigniter

To generate and download a PDF file in CodeIgniter, you can use the TCPDF library along with CodeIgniter’s file helper to create and download the PDF file. Here are the steps to do so:

Install TCPDF in your CodeIgniter project by downloading it from the official website and copying it to the “application/libraries” folder of your project.

Create a controller in your CodeIgniter project to handle the PDF generation and download. For example, you could create a “PdfController.php” file in the “application/controllers” folder.

In the “PdfController.php” file, load the TCPDF library by calling the following code:


To generate the PDF file, create a new instance of the TCPDF class and customize it as desired. For example:

$pdf->SetAuthor('Your Name');
$pdf->SetTitle('Document Title');
$pdf->SetSubject('Document Subject');
$pdf->SetKeywords('keywords, separated, by, commas');
$pdf->SetFont('dejavusans', '', 14);
$pdf->Write(5, 'Hello, World!');

In this example, we create a new instance of the TCPDF class and set some properties such as the creator, author, title, subject, and keywords. We also set the font and add a new page with some text.

To download the PDF file, use CodeIgniter’s file helper to write the PDF output to a file, and then use CodeIgniter’s download helper to force the download of the file. For example:

// Save PDF to file
$pdf_data = $pdf->Output('my_pdf_file.pdf', 'S');
write_file('path/to/folder/my_pdf_file.pdf', $pdf_data);

// Download PDF file
force_download('path/to/folder/my_pdf_file.pdf', NULL);

In this example, we use the TCPDF “Output” method with the ‘S’ parameter to generate the PDF output as a string, and then use CodeIgniter’s “write_file” function to save the PDF to a file. Finally, we use CodeIgniter’s “force_download” function to force the download of the PDF file to the user’s browser.

Note that you can customize the appearance and content of your PDF document using TCPDF’s various methods and properties. You can refer to TCPDF’s documentation for more information:

Angular 6 CRUD Operations Application Tutorials

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about CodeIgniter 3 PDF Generate Tutorial With Example.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment