Posted inProgramming / Codeigniter / Mysql / Mysqli / php

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

application/config/config.php

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

Step 4 : Create a Call mPDF Library in CodeIgniter Controller

CI_Controller

load->view('html_to_pdf',[],true); //CodeIgniter view file name
        $live_mpdf->WriteHTML($all_html);
        $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 Pakainfo.com


 

Welcome to Pakainfo.com!

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 Pakainfo.com Pakainfo.com.

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:

$this->load->library('tcpdf');

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

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Your Name');
$pdf->SetTitle('Document Title');
$pdf->SetSubject('Document Subject');
$pdf->SetKeywords('keywords, separated, by, commas');
$pdf->SetFont('dejavusans', '', 14);
$pdf->AddPage();
$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
$this->load->helper('download');
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: https://tcpdf.org/docs/

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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 Pakainfo.com 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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype