Home » CodeIgniter TCPDF Integration – create pdf page in tcpdf codeigniter

CodeIgniter TCPDF Integration – create pdf page in tcpdf 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 CodeIgniters. we will utilize taking after stride for TCPDF coordination with CodeIgniters.

CodeIgniter TCPDF Integration – create pdf page

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 CodeIgniters(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.

I will utilize tcpdf? Since, I think tcpdf is anything but difficult to utilize :: pdf helper in codeigniter

tcpdf codeigniter
tcpdf codeigniter

Taking after are guideline to include CodeIgniter TCPDF Integration

Step 1 :: for CodeIgniters TCPDF Integration

To Download TCPDF Click Here :: Download TCPDF.

Read Also:  laravel cache clear

Step 2 :: for CodeIgniters TCPDF Integration

Unzip/extract the above download inside at application/libraries/tcpdf.

Step 3 :: for CodeIgniters TCPDF Integration

Create a new file inside at application/libraries/Pdf.php

* Author: pakainfo
* 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()
/* end Pdf.php file */

Also Read: tcpdf example

Step 4 :: for CodeIgniter TCPDF Integration

Create Controller file inside application/controllers/tcpdfexample.php.

* Author: pakainfo
* start tcpdfexample.php file
* Location: ./application/controllers/tcpdfexample.php
class tcpdfexample extends CI_Controller
function __construct()
// add library of Pdf
function index()
// coder for CodeIgniter TCPDF Integration
$tcpdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
// Set Title
$tcpdf->SetTitle('Pdf Example pakainfo');
// Set Header Margin
// Set Top Margin
// set Footer Margin
// Set Auto Page Break
// Set Author
// Set Display Mode
$tcpdf->SetDisplayMode('real', 'default');
// Set Write text
$tcpdf->Write(5, 'CodeIgniter TCPDF Integration - pakainfo');
// Set Output and file name
$tcpdf->Output('tcpdfexample-pakainfo.pdf', 'I');
public function advancetcpdf_example()
// coder for CodeIgniter TCPDF Integration
// make new advance pdf document
// set document information
$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
// set default margins
// Set Header Margin
// Set Footer Margin
// set auto for page breaks
$tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image for scale factor
// it is optional :: set some language-dependent strings
if (@file_exists(dirname(__FILE__).'/lang/eng.php'))
// optional
// optional
// set default font for subsetting mode
// 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.
// 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>
<p>This content is printed utilizing the <i>writeHTMLCell()</i> strategy however you can likewise utilize: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p>
<p>Please check the source code documentation and different cases for further information.</p>
//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-pakainfo.pdf', 'I');
// successfully created CodeIgniter TCPDF Integration
/* end tcpdfexample.php file for CodeIgniter TCPDF Integration */

pdf codeigniter tutorial

Read Also:  How To Add Flash Messages in Laravel 6 Session?

I hope you get an idea about tcpdf codeigniter.
I would like to have feedback on my infinityknow.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.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel 6 Auth Redirection Using redirectTo
  2. Read Also:  Search Filter using Nodejs and MySQL
  3. Read Also:  WooCommerce Get Product Reviews
  4. Read Also:  PHP Inline Editing Table using jQuery Ajax
  5. Read Also:  Laravel 5.7 Bootstrap Admin Panel Templates Integrate
  6. Read Also:  CodeIgniter 3 PDF Generate Tutorial With Example
  7. Read Also:  PHP image manipulation Fits and Fill
  8. Read Also:  PHP cURL Download File From Url Example
  9. Read Also:  Convert Array To Object With PHP
  10. Read Also:  laravel cache clear

Leave a Comment

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