Create PDF with TCPDF, custom Header and Footer

Create Pdf.php file in library folder



<?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();
}
public function Header() {
        // Logo
        $image_file = 'application/libraries/tcpdf/examples/images/laEmailLogo.png'; // *** Very IMP: make sure this image is available on given path on your server
        ///var/www/html/mavensolution_16_07_2016/application/libraries/tcpdf/examples/images
        //echo $image_file;
        $this->Image($image_file,15,6,30);
        // Set font
        $this->SetFont('helvetica', 'C', 12);
   
        // Line break
        $this->Ln();       
        $this->Cell(294, 15, 'Maven Digitech', 0, false, 'C', 0, '', 0, false, 'M', 'M');
        $this->Ln(5);       
        $this->Cell(300, 0, 'LifeAssistant(Unit of MMI)', 0, false, 'C', 0, '', 0, false, 'M', 'M');
        // We need to adjust the x and y positions of this text ... first two parameters
       
    }

    // Page footer
    public function Footer() {
        // Position at 25 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica', 'I', 8);
       
        $this->Cell(0, 0, 'Product Company - Maven Digitech, Phone : +91 1122 3344 55, TIC : LifeAssistant(Unit of MMI)', 0, 0, 'C');
        $this->Ln();
        $this->Cell(0,0,'www.lifeassistant.in - T : +91 1 123 45 64 - E : info@lifeassistant.in', 0, false, 'C', 0, '', 0, false, 'T', 'M');
       
        // Page number
        $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}
/*Author:Tutsway.com */
/* End of file Pdf.php */
/* Location: ./application/libraries/Pdf.php */


Create a function in your controller

public function radheyTcpdfPdf()
        {
            $orderno = $this->uri->segment(3);
            $this->load->helper('file');
            $payoutdetails=$this->vendors->getpayoutPdf($orderno);
           
            // create new PDF document
                $pdf = new PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

                // set document information
                $pdf->SetCreator(PDF_CREATOR);
                $pdf->SetAuthor('Arun');
                $pdf->SetTitle('Payout Invoice');
                $pdf->SetSubject('Payout Invoice');
                $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

                // set default header data
                $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
                // set header and footer fonts
                $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
                $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

                // set default monospaced font
                $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

                // set margins
                $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
                $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
                $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

                // set auto page breaks
                $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

                // set image scale factor
                $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

                // set some language-dependent strings (optional)
                if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
                    require_once(dirname(__FILE__).'/lang/eng.php');
                    $pdf->setLanguageArray($l);
                }

                // ---------------------------------------------------------

                // set font
                $pdf->SetFont('times', 'BI', 12);

                // add a page
                $pdf->AddPage();
                $pdf->setPrintHeader(false);   // remove header from another pages
                $style = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0,64,128));

            //$pdf->Line(2, 15, 205, 15, $style);
            $html=$this->load->view("vendor/tidyTcpdf.php",$payoutdetails,true);
            // Print text using writeHTMLCell()
            //$pdf->writeHTML($html);
            $pdf->writeHTML($html, true, false, false, false, '');
            // set some text to print
            /*
            $txt = <<<EOD
            <?php  echo "test"; ?>
            EOD; */
            // Print text using writeHTMLCell()
            //$pdf->writeHTML($html);
            // print a block of text using Write()
            //$pdf->writeHtml($html);

            // print a block of text using Write()
            //$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);

            // ---------------------------------------------------------

            //Close and output PDF document
            //$pdf->Output('/home/bitnami/mavensolution/assets/invoice.pdf', 'F');
            $pdf->Output('PayoutDetails.pdf', 'D');
       
    }

Create view:

    <table cellpadding="5">
            <tr>
                <td colspan="2" align="center"><u><h1>Invoice</b></h1></td>
            </tr>
            <tr>
                <td colspan="2" align="right"><u><?php echo date("j F, Y"); ?></u></td>
            </tr>
            <tr>
                <td>Dear Radhey,<br>here is your invoice.</td>
            </tr>
    </table><br><br>
    <table width="100%" cellspacing="0" cellpadding="0" border="0" style="font-family: 'Roboto', sans-serif;">
        <tbody>
            <tr>
                <td bgcolor="#fff" width="300">
                    <p style="font-weight:bold;text-transform:capitalize;">Order Id<span style="font-weight:normal;color:#075FC9;">&nbsp;&nbsp;4725-20062018-121729-9200</span></p>
                    <p style="font-weight:bold;text-transform:capitalize;">order date<span style="font-weight:normal;color:#075FC9;">&nbsp;&nbsp;13-11-2017</span></p>
                    <p style="font-weight:bold;text-transform:capitalize;">invoice Number<span style="font-weight:normal;color:#075FC9;">&nbsp;&nbsp;4725-20062018-121729-9200</span></p>
                </td>
                <td bgcolor="#fff" width="205">
                    <p style="margin:0;text-transform:capitalize;font-weight:bold;">delivery address</p>
                    <p>cs-67, 3F ansal plaza, vaishali metro station,ghaziabad(up)</p>
                </td>
                <td bgcolor="#fff" width="205">
                    <p style="margin:0;text-transform:capitalize;font-weight:bold;">Billing Address</p>
                    <p style="margin:0;">cs-67, 3F ansal plaza, vaishali metro station,ghaziabad(up)</p>
                </td>
            </tr>
        </tbody>
    </table><br><br>
    <table width="100%" cellspacing="" cellpadding="5" style="border-collapse:collapse;font-size:12px;border:1px solid #d2d9e7;white-space:normal;font-family: 'Roboto', sans-serif;">
        <tbody>
            <tr style="background-color: #075FC9;color: #ffffff ;text-align: center;font-weight: bold;">
                <td width="20%">
                    <p style="text-transform:capitalize;">payment Method</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">order amount</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">total discount</p>
                </td>
                <td width="20%">
                    <p style="text-transform:uppercase;">gst</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">paid amount</p>
                </td>
            </tr>
            <tr style="text-align: center;">
                <td>Online-Paytm</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
        </tbody>
    </table><br><br>
    <table width="100%" cellspacing="0" cellpadding="0">
        <tbody>
            <tr>
                <td bgcolor="#ffffff" style="text-align: center;">
                    <p style="font-size:14px;text-transform:capitalize;font-weight:normal;text-decoration:underline;">Sub Order
                        details</p>
                </td>
            </tr>
        </tbody>
    </table><br><br>
    <table width="100%" cellspacing="" cellpadding="5" width="100%" cellspacing="" cellpadding="5" style="font-size:12px;border:1px solid #d2d9e7;white-space:normal;font-family: 'Roboto', sans-serif;">
        <tbody>
            <tr style="background-color: #075FC9;color: #ffffff;text-align: center;font-weight: bold;">
                <td width="20%">
                    <p style="text-transform:capitalize;">category Name</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">service Name</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">sub Service</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">service items</p>
                </td>
                <td width="10%">
                    <p style="text-transform:capitalize;">rate</p>
                </td>
                <td width="10%">
                    <p style="text-transform:capitalize;">unit</p>
                </td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>Court/Corporation Related Services</td>
                <td>Indian Certificate Attestation</td>
                <td>Educational Certificate</td>
                <td>1025.00</td>
                <td>5</td>
            </tr>
            <tr style="text-align: center;">
                <td>Taxation & Corporate Consultants</td>
                <td>Capital Gain Calculation/Deposit</td>
                <td>Financial Products</td>
                <td>Financial Products</td>
                <td>8000.00</td>
                <td>1</td>
            </tr>

        </tbody>
    </table><br><br><br><br>
    <table width="100%" cellspacing="" cellpadding="5" style="border-collapse:collapse;font-size:12px;border:1px solid #d2d9e7;white-space:normal;font-family: 'Roboto', sans-serif;">
        <tbody><thead>
            <tr style="background-color: #075FC9;color: #ffffff ;text-transform: capitalize;text-align: center;font-weight: bold;">
                <td width="20%">
                    <p style="text-transform:capitalize;">service Name</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">amount</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">discount</p>
                </td>
                <td width="20%">
                    <p style="text-transform:capitalize;">total Amount</p>
                </td>
                <td width="10%">
                    <p style="text-transform:capitalize;">tax Amount</p>
                </td>
                <td width="10%">
                    <p style="text-transform:capitalize;">paid Amount</p>
                </td>
            </tr>
            </thead>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Taxation & Corporate Consultants</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Taxation & Corporate Consultants</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Taxation & Corporate Consultants</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Taxation & Corporate Consultants</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Taxation & Corporate Consultants</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="text-align: center;">
                <td>Documentation & Certification Assistance</td>
                <td>11000.00</td>
                <td>1000.00</td>
                <td>10000.00</td>
                <td>1000.00</td>
                <td>11000.00</td>
            </tr>
            <tr style="background-color: #075FC9;color: #ffffff ;text-transform: capitalize;text-align: center;font-weight: bold;">
                <td colspan="5">
                    <p style="text-transform: capitalize">sub total</p>
                </td>
                <td>11000.00</td>
            </tr>
        </tbody>
    </table><br><br>
    <table width="100%" cellspacing="" cellpadding="5" style="border-collapse:collapse;font-size:12px;white-space:normal;font-family: 'Roboto', sans-serif;">
        <tbody>
            <tr style="font-weight: bold;text-align: right;">
                <td bgcolor="#ffffff" colspan="5">
                    <p>Total Savings&nbsp;&nbsp;&nbsp;<span style="color:green;">1000.00</span></p>
                    <br />
                    <p>Grand Total&nbsp;&nbsp;11000.00</p>
                </td>
            </tr>
        </tbody>
    </table>

Comments

Popular posts from this blog

Getting started Mysql with JSON

How to get the parameter from url in codeigniter?

MySQL event scheduler and how to create MySQL events to automate database tasks