CodeIgniter TCPDF Integration – create pdf page in CodeIgniter
In this post we will show you how to CodeIgniter TCPDF Integration, TCPDF is PHP class for producing pdf documents.Here we will learn TCPDF incorporation with CodeIgniter. we will utilize taking after stride for TCPDF coordination with CodeIgniter.
Sometimes, we require the report as a pdf or html transformation to pdf. So now we will attempt to disclose how to make pdf page in CodeIgniter(CodeIgniter TCPDF Integration). To make pdf page, we utilize library for making pdf, in this case I will utilize library tcpdf from http://www.tcpdf.org/. Other than utilizing tcpdf, you can likewise utilize another library, for example, fpdf,dompdf, and so on.
You may also like : How to JOIN Tables in Codeigniter
I will utilize tcpdf? Since, I think tcpdf is anything but difficult to utilize ::
Taking after are guideline to include CodeIgniter TCPDF Integration
You may also like : Remove index.php from url in codeigniter
Step 1 :: for CodeIgniter TCPDF Integration
To Download TCPDF Click Here :: Download TCPDF.
Step 2 :: for CodeIgniter TCPDF Integration
Unzip/extract the above download inside at application/libraries/tcpdf
.
Step 3 :: for CodeIgniter TCPDF Integration
Create a new file inside at application/libraries/Pdf.php
<?php /* * Author: onlinecode * start Pdf.php file * Location: ./application/libraries/Pdf.php */ if ( ! defined('BASEPATH')) exit('No direct script access allowed'); require_once dirname(__FILE__) . '/tcpdf/tcpdf.php'; class Pdf extends TCPDF { function __construct() { parent::__construct(); } } /* end Pdf.php file */
Step 4 :: for CodeIgniter TCPDF Integration
Create Controller file inside application/controllers/tcpdfexample.php
.
You may also like : how to Upload file with ajax in codeigniter
/* * Author: onlinecode * start tcpdfexample.php file * Location: ./application/controllers/tcpdfexample.php */ <?php class tcpdfexample extends CI_Controller { function __construct() { parent::__construct(); // add library of Pdf $this->load->library('Pdf'); } function index() { // coder for CodeIgniter TCPDF Integration $tcpdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false); // Set Title $tcpdf->SetTitle('Pdf Example onlinecode'); // Set Header Margin $tcpdf->SetHeaderMargin(30); // Set Top Margin $tcpdf->SetTopMargin(20); // set Footer Margin $tcpdf->setFooterMargin(20); // Set Auto Page Break $tcpdf->SetAutoPageBreak(true); // Set Author $tcpdf->SetAuthor('onlinecode'); // Set Display Mode $tcpdf->SetDisplayMode('real', 'default'); // Set Write text $tcpdf->Write(5, 'CodeIgniter TCPDF Integration - onlinecode'); // Set Output and file name $tcpdf->Output('tcpdfexample-onlinecode.pdf', 'I'); } public function advancetcpdf_example() { // coder for CodeIgniter TCPDF Integration // make new advance pdf document $tcpdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $tcpdf->SetCreator(PDF_CREATOR); $tcpdf->SetAuthor('Muhammad Saqlain Arif'); $tcpdf->SetTitle('TCPDF Example 001'); $tcpdf->SetSubject('TCPDF Tutorial'); $tcpdf->SetKeywords('TCPDF, PDF, example, test, guide'); //set default header information $tcpdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,65,256), array(0,65,127)); $tcpdf->setFooterData(array(0,65,0), array(0,65,127)); //set header textual styles $tcpdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); //set footer textual styles $tcpdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); //set default monospaced textual style $tcpdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set default margins $tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); // Set Header Margin $tcpdf->SetHeaderMargin(PDF_MARGIN_HEADER); // Set Footer Margin $tcpdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto for page breaks $tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image for scale factor $tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // it is optional :: set some language-dependent strings if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { // optional require_once(dirname(__FILE__).'/lang/eng.php'); // optional $tcpdf->setLanguageArray($l); } // set default font for subsetting mode $tcpdf->setFontSubsetting(true); // Set textual style // dejavusans is an UTF-8 Unicode textual style, on the off chance that you just need to // print standard ASCII roasts, you can utilize center text styles like // helvetica or times to lessen record estimate. $tcpdf->SetFont('dejavusans', '', 14, '', true); // Add a new page // This technique has a few choices, check the source code documentation for more data. $tcpdf->AddPage(); // set text shadow for effect $tcpdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,197,198), 'opacity'=>1, 'blend_mode'=>'Normal')); /Set some substance to print $set_html = <<<EOD <h1>Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0001;color:black;"> <span style="color:black;">TC</span><span style="color:white;">PDF Example</span> </a>!</h1> <i>This is the principal case of TCPDF library.</i> This content is printed utilizing the <i>writeHTMLCell()</i> strategy however you can likewise utilize: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>. Please check the source code documentation and different cases for further information. EOD; //Print content utilizing writeHTMLCell() $tcpdf->writeHTMLCell(0, 0, '', '', $set_html, 0, 1, 0, true, '', true); // Close and yield PDF record // This technique has a few choices, check the source code documentation for more data. $tcpdf->Output('tcpdfexample-onlinecode.pdf', 'I'); // successfully created CodeIgniter TCPDF Integration } } /* end tcpdfexample.php file for CodeIgniter TCPDF Integration */ ?>
Hope this code and post will helped you for implement CodeIgniter TCPDF Integration – create pdf page in CodeIgniter. if you need any help or any feedback give it in the comment section or you have a good idea about this post you can give it a comment section. Your comment will help us to help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs https://onlinecode.org
Thanks 🙂
God Bless