How to show unique value on tcpdf? - php

Reference - http://i.stack.imgur.com/oAIbz.png
foreach($data as $k=>$v){
//print_r($v);
exit;
if ($yr != $v['year']) {
$pdf->SetFont('helvetica', 'B',9);
$pdf->Cell(25,4, 'Payment Year :',0,0,'L', false,'',0,false,'T','M');
$pdf->SetFont('helvetica', '',9);
$pdf->Cell(10,4, $v['year'],0,1,'L', false,'',0,false,'T','M');
//header
$pdf->SetFont('helvetica', 'B',9);
$pdf->Cell(67,4, 'Student',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(30,4, $v['year'].' Class',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(47,4, 'Fee',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(20,4, 'Amount',1,0,'C', false,'',0,false,'T','M');
$pdf->Cell(20,4, 'Total',1,1,'C', false,'',0,false,'T','M');
$pdf->SetFont('helvetica', '',9);
//$total1 = $total1 + $v['amount'];
$total1 = 0;
$yr = $v['year'];
}
$pdf->MultiCell(67, 4, $v['student_name'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$pdf->MultiCell(30, 4, $v['class_english_name'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$pdf->MultiCell(47, 4, $v['fee_group_desc'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$pdf->MultiCell(20, 4, '*'.number_format($v['amount'],2), 1, 'C', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$total1 = $total1 + $v['amount'];
$total2 = $total2 + $v['amount'];
$pdf->MultiCell(20, 4, number_format($total1,2), 1, 'C', 0, 1, '', '', true, 0, false, true, 8, 'T', false);
`

i guess your in some kind of loop? you need to store the fact that you have used the name, and for the rest of the loop check if you have used the name to determine if you need to display it again
outside the loop
$name_used=FALSE;//default to false
then in your loop
if(!$name_used){
$pdf->MultiCell(67, 4, $v['student_name'], 1, 'L', 0, 0, '', '', true, 0, false, true, 8, 'T', false);
$name_used=TRUE;//after first time through loop make this true, so name not used again
}else{
//maybe noting, maybe a blank cell
}

Related

TCPDF is not working on an online server after hosting while was working on localhost, how solve this error? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 days ago.
Improve this question
I created a PHP Web App on localhost. With the app I was able to download PDFs while it was still on localhost. I then uploaded the app, meaning hosted it. I am able to login and navigate through the app, but I am unable to download the PDFs now. I am using TCPDF.
Please kindly help me resolve this issue.
Below is the code where I am creating the PDF file with the data from the Database.
<?php include('includes/header.php'); ?>
<?php include('https://www.gigabittech.com/includes/session.php'); ?>
<?php include('https://www.gigabittech.com/includes/config.php'); ?>
<?php
/* require 'config.php'; */
require('https://www.gigabittech.com/info_file/tcpdf.php');
if (isset($_GET['pdf_report_generate'])){
$empID = $_GET['empID'];
$select = "SELECT * FROM tblemployees WHERE emp_id='$empID'";
$query = mysqli_query($conn, $select);
while ($row = mysqli_fetch_array($query)){
$bs_num=$row['BS_Number'];
$title=$row['Title'];
$lname = $row['LastName'];
$fname = $row['FirstName'];
$nname = $row['Nickname'];
$startDate=$row['Start_Date'];
$dob=$row['Dob'];
$pid=$row['PIN'];
$passport_number=$row['Passport_Number'];
$passport_country_code=$row['Passport_Country_Code'];
$gender=$row['Gender'];
$marital_status=$row['Marital_Status'];
$dependents=$row['Dependants'];
$residential_address_unit_number=$row['Residential_Address_Unit_Number'];
$residential_address_complex=$row['Residential_Address_Complex'];
$residential_address_street_number=$row['Residential_Address_Street_Number'];
$residential_address_street_name_farm=$row['Residential_Address_Street_Name_Farm'];
$residential_address_suburb_district=$row['Residential_Address_Suburb_District'];
$residential_address_city_town=$row['Residential_Address_City_Town'];
$residential_address_post_code=$row['Residential_Address_Post_Code'];
$postal_address=$row['Postal_Address'];
$postal_address_2=$row['Postal_Address_2'];
$postal_address_3=$row['Postal_Address_3'];
$postal_address_4=$row['Postal_Address_4'];
$postal_address_5=$row['Postal_Address_5'];
$business_address_code=$row['Business_Address_Code'];
$work_phone_number=$row['Work_Phone_Number'];
$home_tel_num=$row['Home_Tel_Num'];
$phonenumber=$row['Phonenumber'];
$fax_number=$row['Fax_Number'];
$next_of_kin_name=$row['Next_Of_Kin_Name'];
$next_of_kin_number=$row['Next_Of_Kin_Number'];
$email = $row['EmailId'];
$costcentre=$row['Cost_Centre'];
$jobdescription=$row['Job_Description'];
$branch_code=$row['Branch_Code'];
$account_number=$row['Account_Number'];
$account_holders_name=$row['Account_Holders_Name'];
$graded_tax=$row['Graded_Tax'];
$name_head_parental_home=$row['Name_Head_Parental_Home'];
$address=$row['Address'];
$parental_home_address_line_2=$row['Parental_Home_Address_Line_2'];
$parental_home_address_line_3=$row['Parental_Home_Address_Line_3'];
$parental_home_address_line_4=$row['Parental_Home_Address_Line_4'];
$parental_home_tel_num=$row['Parental_Home_Tel_Num'];
$chief=$row['Chief'];
$user_role=$row['role'];
$department=$row['Department'];
}
}
class PDF extends TCPDF{
public function Header(){
$imageFile = K_PATH_IMAGES.'bns-spar-logo.png';
$this->Image($imageFile, 15, 2, 100, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->Ln(5);
}
public function Footer(){
$this->setY(-30); // POSITION AT 15mm FROM THE BOTTOM OF THE PAGE
$this->Ln(5);
$this->setFont('helvetica','B',12);
$this->Cell(189, 5,'GIGABIT TECHNOLOGIES (PTY) LTD.' ,0,1,'C');
$this->setFont('helvetica','',8);
$this->Cell(189, 4,'P.O. Box 1844 Manzini' ,0,1,'C');
$this->Cell(189, 4,'Email: sales#gigabittech.com | Tel: +268 7672 4277' ,0,1,'C');
$this->Cell(189, 4,'Office 786, Manzini Lifestyle Centre, Plot 2871, Ngwane Street, Manzini' ,0,1,'C');
$this->setFont('helvetica','',8);
date_default_timezone_set("Asia/Dhaka");
$today = date("F j, Y");
$this->Cell(25, 10, 'Printed On: '.$today,0,0,'L');
$this->Cell(164, 10, 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new PDF('P', 'mm', 'A4', true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nkambule Bonginkosi');
$pdf->SetTitle('BNS Employee Contract');
$pdf->SetSubject('BNS Employee Contract');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// 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 default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('helvetica', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
$pdf->Ln(1);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(189, 1, 'EMPLOYEE INFORMATION', 0, 1, 'C');
$pdf->Ln(5);
$pdf->setFillColor(204, 197, 197);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'SURNAME', 1, 0,'',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $lname, 1, 1);
$pdf->Ln(0);
$pdf->setFillColor(204, 197, 197);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'NAMES', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $fname, 1, 1);
$pdf->Ln(0);
$pdf->setFillColor(204, 197, 197);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS', 1, 0, '',1);
$pdf->Cell(70, 1, 'POSTAL', 1, 0, '', 1);
$pdf->Cell(69, 1, 'PHYSICAL', 1, 0, '',1);
$pdf->Ln(4.5);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(10, 15, '', 0, 'L', 0, 0, '', '', true);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(70, 15, '', 0, 'L', 0, 0, 25, '', true);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(70, 15, 'P.O. '.$postal_address, 1, 'L', 0, 0, 65, '', true);
$pdf->Ln(4.5);
$pdf->MultiCell(70, 15, $postal_address_3, 1, 'L', 0, 0, 65, '', true);
$pdf->Ln(5.2);
$pdf->MultiCell(70, 15, $postal_address_5, 1, 'L', 0, 1, 65, '', true);
$pdf->Ln(-25);
$pdf->MultiCell(69, 15, $address, 1, 'L', 0, 0, 135, '', true);
$pdf->Ln(10);
$pdf->MultiCell(69, 15, $residential_address_unit_number, 1, 'L', 0, 0, 135, '', true);
$pdf->Ln(6);
$pdf->MultiCell(70, 15, $residential_address_city_town, 0, 'L', 0, 0, 135, '', true);
$pdf->Ln(13);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'CELL NUM.', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $phonenumber, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ID NUMBER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $pid, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'TAX NUMBER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $graded_tax, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'D.O.B', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $dob, 1, 1, '',0);
/* $pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(20, 1, 'NATIONALITY', 0, 0);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(129, 1, $nationality, 0, 1); */
if ($gender == 1){
$real_gender = "Female";
} else {
$real_gender = "Male";
}
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'GENDER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $real_gender, 1, 1, '',0);
if ($marital_status == 1){
$real_marital_status = "Married";
} else {
$real_marital_status = "Single";
}
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'MARITAL STATUS', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $real_marital_status, 1, 1, '',0);
// SPOUSE START
/* $pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(20, 1, 'SPOUSE', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'NAME', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, 'CONTACT NUMBER', 0, 0);
$pdf->Ln(6);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(20, 1, ' ', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, $spouse_name, 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, $spouse_number, 0, 1);
$pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(20, 1, '', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'ID NUMBER', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, '', 0, 0);
$pdf->Ln(6);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(20, 1, ' ', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, $spouse_id_number, 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, '', 0, 1); */
// SPOUSE END
// NEXT OF KIN START
$pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'NEXT OF KIN', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(70, 1, 'NAME', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, 'CONTACT NUMBER', 1, 1, '',1);
$pdf->Ln(0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(50, 1, ' ', 0, 0);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(70, 1, $next_of_kin_name, 1, 0, '',0);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, $next_of_kin_number, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(189, 1, 'PARENTAL HOME DETAILS', 0, 1, 'C');
$pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'PARENTAL HOME HEAD', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $name_head_parental_home, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS LINE 1', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $parental_home_address_line_2, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS LINE 2', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $parental_home_address_line_3, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS LINE 3', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $parental_home_address_line_4, 1, 1, '',0);
/* $pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(20, 1, '', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'RELATIONSHIP', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, '', 0, 0);
$pdf->Ln(5);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(20, 1, ' ', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, $next_of_kin_realtionship, 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, '', 0, 1); */
// NEXT OF KIN END
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(189, 1, 'BANKING DETAILS', 0, 1, 'C');
$pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ACCOUNT HOLDER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $lname.' '.$fname, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ACCOUNT NUMBER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $account_number, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'BRANCH CODE', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $branch_code, 1, 1, '',0);
/* $pdf->Ln(26);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'BANK DETAILS', 1, 0, '',1);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'BANK NAME', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(69, 1, $bank_name, 0, 0); */
/* $pdf->Ln(0);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, '', 0, 0);
$pdf->Cell(70, 1, 'ACC. HOLDER', 1, 0, '',1);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(69, 1, $lname.' '.$fname, 1, 0, '',0);
$pdf->Ln(4.6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, '', 0, 0);
$pdf->Cell(70, 1, 'ACC. NUMBER', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(69, 1, $account_number, 1, 0, '',0);
$pdf->Ln(4.6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, '', 0, 0);
$pdf->Cell(70, 1, 'BRANCH CODE', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(69, 1, $branch_code, 1, 0, '',0); */
/* $pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(20, 1, '', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'ACC. TYPE', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(69, 1, $account_type, 0, 0); */
$pdf->Ln(32);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(10, 1, '___________________________________', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Ln(6);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(100, 15, 'Signature: '.$title.' '.$lname.' '.$fname, 0, 'L', 0, 0, 15, '', true);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Ln(-6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->MultiCell(100, 15, '___________________________________', 0, 'L', 0, 0, 120, '', true);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Ln(6);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(100, 15, 'Date', 0, 'L', 0, 0, 120, '', true);
$pdf->Cell(30, 1, ' ', 0, 0);
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
ob_end_clean();
$pdf->Output($fname." Info.pdf", 'I');
?>
Below is the code that I was using while on localhost and it still the one on the online server.
<?php include('includes/header.php'); ?>
<?php include('https://www.gigabittech.com/includes/session.php'); ?>
<?php include('https://www.gigabittech.com/includes/config.php'); ?>
<?php
/* require 'config.php'; */
require('https://www.gigabittech.com/info_file/tcpdf.php');
if (isset($_GET['pdf_report_generate'])){
$empID = $_GET['empID'];
$select = "SELECT * FROM tblemployees WHERE emp_id='$empID'";
$query = mysqli_query($conn, $select);
while ($row = mysqli_fetch_array($query)){
$bs_num=$row['BS_Number'];
$title=$row['Title'];
$lname = $row['LastName'];
$fname = $row['FirstName'];
$nname = $row['Nickname'];
$startDate=$row['Start_Date'];
$dob=$row['Dob'];
$pid=$row['PIN'];
$passport_number=$row['Passport_Number'];
$passport_country_code=$row['Passport_Country_Code'];
$gender=$row['Gender'];
$marital_status=$row['Marital_Status'];
$dependents=$row['Dependants'];
$residential_address_unit_number=$row['Residential_Address_Unit_Number'];
$residential_address_complex=$row['Residential_Address_Complex'];
$residential_address_street_number=$row['Residential_Address_Street_Number'];
$residential_address_street_name_farm=$row['Residential_Address_Street_Name_Farm'];
$residential_address_suburb_district=$row['Residential_Address_Suburb_District'];
$residential_address_city_town=$row['Residential_Address_City_Town'];
$residential_address_post_code=$row['Residential_Address_Post_Code'];
$postal_address=$row['Postal_Address'];
$postal_address_2=$row['Postal_Address_2'];
$postal_address_3=$row['Postal_Address_3'];
$postal_address_4=$row['Postal_Address_4'];
$postal_address_5=$row['Postal_Address_5'];
$business_address_code=$row['Business_Address_Code'];
$work_phone_number=$row['Work_Phone_Number'];
$home_tel_num=$row['Home_Tel_Num'];
$phonenumber=$row['Phonenumber'];
$fax_number=$row['Fax_Number'];
$next_of_kin_name=$row['Next_Of_Kin_Name'];
$next_of_kin_number=$row['Next_Of_Kin_Number'];
$email = $row['EmailId'];
$costcentre=$row['Cost_Centre'];
$jobdescription=$row['Job_Description'];
$branch_code=$row['Branch_Code'];
$account_number=$row['Account_Number'];
$account_holders_name=$row['Account_Holders_Name'];
$graded_tax=$row['Graded_Tax'];
$name_head_parental_home=$row['Name_Head_Parental_Home'];
$address=$row['Address'];
$parental_home_address_line_2=$row['Parental_Home_Address_Line_2'];
$parental_home_address_line_3=$row['Parental_Home_Address_Line_3'];
$parental_home_address_line_4=$row['Parental_Home_Address_Line_4'];
$parental_home_tel_num=$row['Parental_Home_Tel_Num'];
$chief=$row['Chief'];
$user_role=$row['role'];
$department=$row['Department'];
}
}
class PDF extends TCPDF{
public function Header(){
$imageFile = K_PATH_IMAGES.'bns-spar-logo.png';
$this->Image($imageFile, 15, 2, 100, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->Ln(5);
}
public function Footer(){
$this->setY(-30); // POSITION AT 15mm FROM THE BOTTOM OF THE PAGE
$this->Ln(5);
$this->setFont('helvetica','B',12);
$this->Cell(189, 5,'GIGABIT TECHNOLOGIES (PTY) LTD.' ,0,1,'C');
$this->setFont('helvetica','',8);
$this->Cell(189, 4,'P.O. Box 1844 Manzini' ,0,1,'C');
$this->Cell(189, 4,'Email: sales#gigabittech.com | Tel: +268 7672 4277' ,0,1,'C');
$this->Cell(189, 4,'Office 786, Manzini Lifestyle Centre, Plot 2871, Ngwane Street, Manzini' ,0,1,'C');
// SETTING FONT
$this->setFont('helvetica','',8);
// PAGE NUMBER
date_default_timezone_set("Asia/Dhaka");
$today = date("F j, Y");
$this->Cell(25, 10, 'Printed On: '.$today,0,0,'L');
$this->Cell(164, 10, 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new PDF('P', 'mm', 'A4', true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nkambule Bonginkosi');
$pdf->SetTitle('BNS Employee Contract');
$pdf->SetSubject('BNS Employee Contract');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// 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 default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('helvetica', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
$pdf->Ln(1);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(189, 1, 'EMPLOYEE INFORMATION', 0, 1, 'C');
$pdf->Ln(5);
$pdf->setFillColor(204, 197, 197);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'SURNAME', 1, 0,'',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $lname, 1, 1);
$pdf->Ln(0);
$pdf->setFillColor(204, 197, 197);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'NAMES', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $fname, 1, 1);
$pdf->Ln(0);
$pdf->setFillColor(204, 197, 197);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS', 1, 0, '',1);
$pdf->Cell(70, 1, 'POSTAL', 1, 0, '', 1);
$pdf->Cell(69, 1, 'PHYSICAL', 1, 0, '',1);
$pdf->Ln(4.5);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(10, 15, '', 0, 'L', 0, 0, '', '', true);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(70, 15, '', 0, 'L', 0, 0, 25, '', true);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(70, 15, 'P.O. '.$postal_address, 1, 'L', 0, 0, 65, '', true);
$pdf->Ln(4.5);
$pdf->MultiCell(70, 15, $postal_address_3, 1, 'L', 0, 0, 65, '', true);
$pdf->Ln(5.2);
$pdf->MultiCell(70, 15, $postal_address_5, 1, 'L', 0, 1, 65, '', true);
$pdf->Ln(-25);
$pdf->MultiCell(69, 15, $address, 1, 'L', 0, 0, 135, '', true);
$pdf->Ln(10);
$pdf->MultiCell(69, 15, $residential_address_unit_number, 1, 'L', 0, 0, 135, '', true);
$pdf->Ln(6);
$pdf->MultiCell(70, 15, $residential_address_city_town, 0, 'L', 0, 0, 135, '', true);
$pdf->Ln(13);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'CELL NUM.', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $phonenumber, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ID NUMBER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $pid, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'TAX NUMBER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $graded_tax, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'D.O.B', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $dob, 1, 1, '',0);
if ($gender == 1){
$real_gender = "Female";
} else {
$real_gender = "Male";
}
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'GENDER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $real_gender, 1, 1, '',0);
if ($marital_status == 1){
$real_marital_status = "Married";
} else {
$real_marital_status = "Single";
}
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'MARITAL STATUS', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(139, 1, $real_marital_status, 1, 1, '',0);
// NEXT OF KIN START
$pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'NEXT OF KIN', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(70, 1, 'NAME', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, 'CONTACT NUMBER', 1, 1, '',1);
$pdf->Ln(0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(50, 1, ' ', 0, 0);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(70, 1, $next_of_kin_name, 1, 0, '',0);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, $next_of_kin_number, 1, 1, '',0);
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(189, 1, 'PARENTAL HOME DETAILS', 0, 1, 'C');
$pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'PARENTAL HOME HEAD', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $name_head_parental_home, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS LINE 1', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $parental_home_address_line_2, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS LINE 2', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $parental_home_address_line_3, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ADDRESS LINE 3', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $parental_home_address_line_4, 1, 1, '',0);
/* $pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(20, 1, '', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'RELATIONSHIP', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, '', 0, 0);
$pdf->Ln(5);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(20, 1, ' ', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, $next_of_kin_realtionship, 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(69, 1, '', 0, 1); */
// NEXT OF KIN END
$pdf->Ln(4);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(189, 1, 'BANKING DETAILS', 0, 1, 'C');
$pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ACCOUNT HOLDER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $lname.' '.$fname, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'ACCOUNT NUMBER', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $account_number, 1, 1, '',0);
$pdf->Ln(2);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'BRANCH CODE', 1, 0, '',1);
$pdf->setFont('helvetica', '', 10);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(139, 1, $branch_code, 1, 1, '',0);
/* $pdf->Ln(26);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, 'BANK DETAILS', 1, 0, '',1);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'BANK NAME', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(69, 1, $bank_name, 0, 0); */
/* $pdf->Ln(0);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, '', 0, 0);
$pdf->Cell(70, 1, 'ACC. HOLDER', 1, 0, '',1);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(69, 1, $lname.' '.$fname, 1, 0, '',0);
$pdf->Ln(4.6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, '', 0, 0);
$pdf->Cell(70, 1, 'ACC. NUMBER', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(69, 1, $account_number, 1, 0, '',0);
$pdf->Ln(4.6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(50, 1, '', 0, 0);
$pdf->Cell(70, 1, 'BRANCH CODE', 1, 0, '',1);
// $pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 10);
$pdf->Cell(69, 1, $branch_code, 1, 0, '',0); */
/* $pdf->Ln(6);
$pdf->setFont('helvetica', 'B', 12);
$pdf->Cell(20, 1, '', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Cell(40, 1, 'ACC. TYPE', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->setFont('helvetica', '', 12);
$pdf->Cell(69, 1, $account_type, 0, 0); */
$pdf->Ln(32);
$pdf->setFont('helvetica', 'B', 10);
$pdf->Cell(10, 1, '___________________________________', 0, 0);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Ln(6);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(100, 15, 'Signature: '.$title.' '.$lname.' '.$fname, 0, 'L', 0, 0, 15, '', true);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Ln(-6);
$pdf->setFont('helvetica', 'B', 10);
$pdf->MultiCell(100, 15, '___________________________________', 0, 'L', 0, 0, 120, '', true);
$pdf->Cell(30, 1, ' ', 0, 0);
$pdf->Ln(6);
$pdf->setFont('helvetica', '', 10);
$pdf->MultiCell(100, 15, 'Date', 0, 'L', 0, 0, 120, '', true);
$pdf->Cell(30, 1, ' ', 0, 0);
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
ob_end_clean();
$pdf->Output($fname." Info.pdf", 'I');
?>

PDF - barcode printing is always failing with TCPDF

I am always getting:
TCPDF ERROR: Error in 1D barcode string
On
public function testingAction() {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
require_once(APPLICATION_PATH . '/models/tcpdf/config/lang/eng.php');
require_once(APPLICATION_PATH . '/models/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 027');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 027', 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 a barcode on the page footer
$pdf->setBarcode(date('Y-m-d H:i:s'));
// set font
$pdf->SetFont('helvetica', '', 11);
// add a page
$pdf->AddPage();
// print a message
$txt = "You can also export 1D barcodes in other formats (PNG, SVG, HTML). Check the examples inside the barcodes directory.\n";
$pdf->MultiCell(70, 50, $txt, 0, 'J', false, 1, 125, 30, true, 0, false, true, 0, 'T', false);
$pdf->SetY(30);
// -----------------------------------------------------------------------------
$pdf->SetFont('helvetica', '', 10);
// define barcode style
$style = array(
'position' => '',
'align' => 'C',
'stretch' => false,
'fitwidth' => true,
'cellfitalign' => '',
'border' => true,
'hpadding' => 'auto',
'vpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255),
'text' => true,
'font' => 'helvetica',
'fontsize' => 8,
'stretchtext' => 4
);
// PRINT VARIOUS 1D BARCODES
// CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
$pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
$pdf->write1DBarcode('CODE 39', 'C39', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 39 + CHECKSUM
$pdf->Cell(0, 0, 'CODE 39 + CHECKSUM', 0, 1);
$pdf->write1DBarcode('CODE 39 +', 'C39+', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 39 EXTENDED
$pdf->Cell(0, 0, 'CODE 39 EXTENDED', 0, 1);
$pdf->write1DBarcode('CODE 39 E', 'C39E', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 39 EXTENDED + CHECKSUM
$pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
$pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 93 - USS-93
$pdf->Cell(0, 0, 'CODE 93 - USS-93', 0, 1);
$pdf->write1DBarcode('TEST93', 'C93', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// Standard 2 of 5
$pdf->Cell(0, 0, 'Standard 2 of 5', 0, 1);
$pdf->write1DBarcode('1234567', 'S25', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// Standard 2 of 5 + CHECKSUM
$pdf->Cell(0, 0, 'Standard 2 of 5 + CHECKSUM', 0, 1);
$pdf->write1DBarcode('1234567', 'S25+', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// Interleaved 2 of 5
$pdf->Cell(0, 0, 'Interleaved 2 of 5', 0, 1);
$pdf->write1DBarcode('1234567', 'I25', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// Interleaved 2 of 5 + CHECKSUM
$pdf->Cell(0, 0, 'Interleaved 2 of 5 + CHECKSUM', 0, 1);
$pdf->write1DBarcode('1234567', 'I25+', '', '', '', 18, 0.4, $style, 'N');
// add a page ----------
$pdf->AddPage();
// CODE 128 AUTO
$pdf->Cell(0, 0, 'CODE 128 AUTO', 0, 1);
$pdf->write1DBarcode('CODE 128 AUTO', 'C128', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 128 A
$pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
$pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 128 B
$pdf->Cell(0, 0, 'CODE 128 B', 0, 1);
$pdf->write1DBarcode('CODE 128 B', 'C128B', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 128 C
$pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
$pdf->write1DBarcode('0123456789', 'C128C', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// EAN 8
$pdf->Cell(0, 0, 'EAN 8', 0, 1);
$pdf->write1DBarcode('1234567', 'EAN8', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// EAN 13
$pdf->Cell(0, 0, 'EAN 13', 0, 1);
$pdf->write1DBarcode('1234567890128', 'EAN13', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// UPC-A
$pdf->Cell(0, 0, 'UPC-A', 0, 1);
$pdf->write1DBarcode('12345678901', 'UPCA', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// UPC-E
$pdf->Cell(0, 0, 'UPC-E', 0, 1);
$pdf->write1DBarcode('04210000526', 'UPCE', '', '', '', 18, 0.4, $style, 'N');
// add a page ----------
$pdf->AddPage();
// 5-Digits UPC-Based Extension
$pdf->Cell(0, 0, '5-Digits UPC-Based Extension', 0, 1);
$pdf->write1DBarcode('51234', 'EAN5', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// 2-Digits UPC-Based Extension
$pdf->Cell(0, 0, '2-Digits UPC-Based Extension', 0, 1);
$pdf->write1DBarcode('34', 'EAN2', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// MSI
$pdf->Cell(0, 0, 'MSI', 0, 1);
$pdf->write1DBarcode('80523', 'MSI', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// MSI + CHECKSUM (module 11)
$pdf->Cell(0, 0, 'MSI + CHECKSUM (module 11)', 0, 1);
$pdf->write1DBarcode('80523', 'MSI+', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODABAR
$pdf->Cell(0, 0, 'CODABAR', 0, 1);
$pdf->write1DBarcode('123456789', 'CODABAR', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// CODE 11
$pdf->Cell(0, 0, 'CODE 11', 0, 1);
$pdf->write1DBarcode('123-456-789', 'CODE11', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// PHARMACODE
$pdf->Cell(0, 0, 'PHARMACODE', 0, 1);
$pdf->write1DBarcode('789', 'PHARMA', '', '', '', 18, 0.4, $style, 'N');
$pdf->Ln();
// PHARMACODE TWO-TRACKS
$pdf->Cell(0, 0, 'PHARMACODE TWO-TRACKS', 0, 1);
$pdf->write1DBarcode('105', 'PHARMA2T', '', '', '', 18, 2, $style, 'N');
// add a page ----------
$pdf->AddPage();
// IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
$pdf->Cell(0, 0, 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200', 0, 1);
$pdf->write1DBarcode('01234567094987654321-01234567891', 'IMB', '', '', '', 15, 0.6, $style, 'N');
$pdf->Ln();
// POSTNET
$pdf->Cell(0, 0, 'POSTNET', 0, 1);
$pdf->write1DBarcode('98000', 'POSTNET', '', '', '', 15, 0.6, $style, 'N');
$pdf->Ln();
// PLANET
$pdf->Cell(0, 0, 'PLANET', 0, 1);
$pdf->write1DBarcode('98000', 'PLANET', '', '', '', 15, 0.6, $style, 'N');
$pdf->Ln();
// RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
$pdf->Cell(0, 0, 'RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)', 0, 1);
$pdf->write1DBarcode('SN34RD1A', 'RMS4CC', '', '', '', 15, 0.6, $style, 'N');
$pdf->Ln();
// KIX (Klant index - Customer index)
$pdf->Cell(0, 0, 'KIX (Klant index - Customer index)', 0, 1);
$pdf->write1DBarcode('SN34RDX1A', 'KIX', '', '', '', 15, 0.6, $style, 'N');
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TEST BARCODE ALIGNMENTS
// add a page
$pdf->AddPage();
// set a background color
$style['bgcolor'] = array(255,255,240);
$style['fgcolor'] = array(127,0,0);
// Left position
$style['position'] = 'L';
$pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Center position
$style['position'] = 'C';
$pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Right position
$style['position'] = 'R';
$pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
$style['fgcolor'] = array(0,127,0);
$style['position'] = '';
$style['stretch'] = false; // disable stretch
$style['fitwidth'] = false; // disable fitwidth
// Left alignment
$style['align'] = 'L';
$pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Center alignment
$style['align'] = 'C';
$pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Right alignment
$style['align'] = 'R';
$pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
$style['fgcolor'] = array(0,64,127);
$style['position'] = '';
$style['stretch'] = false; // disable stretch
$style['fitwidth'] = true; // disable fitwidth
// Left alignment
$style['cellfitalign'] = 'L';
$pdf->write1DBarcode('LEFT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Center alignment
$style['cellfitalign'] = 'C';
$pdf->write1DBarcode('CENTER', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Right alignment
$style['cellfitalign'] = 'R';
$pdf->write1DBarcode('RIGHT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
$pdf->Ln(2);
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
$style['fgcolor'] = array(127,0,127);
// Left alignment
$style['position'] = 'L';
$pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Center alignment
$style['position'] = 'C';
$pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
$pdf->Ln(2);
// Right alignment
$style['position'] = 'R';
$pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TEST BARCODE STYLE
// define barcode style
$style = array(
'position' => '',
'align' => '',
'stretch' => true,
'fitwidth' => false,
'cellfitalign' => '',
'border' => true,
'hpadding' => 'auto',
'vpadding' => 'auto',
'fgcolor' => array(0,0,128),
'bgcolor' => array(255,255,128),
'text' => true,
'label' => 'CUSTOM LABEL',
'font' => 'helvetica',
'fontsize' => 8,
'stretchtext' => 4
);
// CODE 39 EXTENDED + CHECKSUM
$pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
$pdf->SetLineStyle(array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
$pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', 120, 25, 0.4, $style, 'N');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_027.pdf', 'I');
}
Could somebody please help me with this?
EDIT: working
public function apprintAction() {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
require_once(APPLICATION_PATH . '/models/tcpdf/config/lang/eng.php');
require_once(APPLICATION_PATH . '/models/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
// 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(0);
$pdf->SetFooterMargin(0);
$pdf->setPrintFooter(false);
//$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetAutoPageBreak(false, 0);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->setFontSubsetting(true);
$pdf->SetFont('dejavusans', '', 8, '', true);
$pdf->setPrintHeader(false);
// Connect to DataBase
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'production');
$db = Zend_Db::factory($config->resources->db);
$kiosk = $_GET['kiosk'];
$sql = "select *from table0 where kiosk='{$kiosk}' and task='print' order by id desc limit 1";
$result = $db->fetchAll($sql);
if(count($result) > 0 ){
$qr_code = '';
// Collect the QR code here
$sql = "select *from table1 where rrn='{$result[0]['rrn']}' and firstname='{$result[0]['firstname']}' and lastname='{$result[0]['lastname']}' order by id desc limit 1";
$result1 = $db->fetchAll($sql);
if(count($result1)> 0) {
$qr_code = $result1[0]['picture'];
}
$gape = 20;
$width = 30;
$sql = "select *from table2 where rd='{$result[0]['rrn']}'";
$result2 = $db->fetchAll($sql);
if(count($result2)>0) {
foreach($result2 as $k=>$v) {
$pdf->AddPage();
$img_file = APPLICATION_PATH . '/models/fpdi/en.jpg';
$pdf->Image($img_file, 0, -10, 190, 300, '', '', '', true, 300, 'C', false, false, 0);
$pdf->writeHTMLCell(80, '', 78, 25, $result2[$k]['e'], 1, 0, 1, true, 'J', true);
$pdf->writeHTMLCell(80, '', 78, 55, $result2[$k]['d'], 1, 0, 1, true, 'J', true);
$pdf->writeHTMLCell(80, '', 78, 65, $result2[$k]['c'], 1, 0, 1, true, 'J', true);
$pdf->writeHTMLCell(80, '', 78, 74, $result2[$k]['b'], 1, 0, 1, true, 'J', true);
$pdf->writeHTMLCell(80, '', 78, 84, $result2[$k]['a'], 1, 0, 1, true, 'J', true);
$pdf->writeHTMLCell(160, '', 19, 185, $qr_code, 1, 0, 1, true, 'J', true);
// Get the QR-code
if($qr_code!='') {
try{
$pdf->SetFont('helvetica', '', 10);
$style = array(
'border' => 2,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255)
'module_width' => 1, // width of a single module in points
'module_height' => 1 // height of a single module in points
);
$pdf->write2DBarcode('www.tcpdf.org', 'PDF417', 20, 195, 0, 30, $style, 'N');
//$pdf->write1DBarcode($qr_code, 'C128', 18, 190, $width, 13, 0, $style, 'N');
}catch(Exception $eo) { }
}
// Get the Bar-codes from the list
$style = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array( 0, 0, 0 ),
'bgcolor' => false,
'stretch' => 1, 'text' => true
);
$pdf->write1DBarcode('00112233449', 'EAN13', 25, 195 +40, $width, 13, 0, $style, 'N');
}
}
}
$pdf->Output('a4', 'I');
}
If you want to place the 1D barcode on page footer, then you may simply extend the TCPDF class:
public function testingAction() {
require_once(APPLICATION_PATH . '/models/tcpdf/config/lang/eng.php');
require_once(APPLICATION_PATH . '/models/tcpdf/tcpdf.php');
class MYTCPDF extends TCPDF{
public function Footer(){
$barcode = $this->getBarcode();
if( !empty( $barcode ) ){
$style = array(
'border' => 0,
'vpadding' => 'auto',
'hpadding' => 'auto',
'fgcolor' => array( 0, 0, 0 ),
'bgcolor' => false,
'stretch' => 1
);
$this->write1DBarcode( $barcode, 'EAN13', 84, 4, 75, 13, 0, $style, 'N' );
}
}
}
$pdf = new MYTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setBarcode( date('Y-m-d H:i:s') );
}
UPDATE
According to this quote from OP's comment
I need to place it bottom of the page where i have some space
I will provide this snippet
public function testingAction() {
require_once(APPLICATION_PATH . '/models/tcpdf/config/lang/eng.php');
require_once(APPLICATION_PATH . '/models/tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 027');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$params = $pdf->serializeTCPDFtagParameters(
array(
date('Y-m-d H:i:s'), 'C39', '', '', 80, 30, 0.4,
array(
'position'=>'S',
'border'=>true,
'padding'=>4,
'fgcolor'=>array(0,0,0),
'bgcolor'=>array(255,255,255),
'text'=>true,
'font'=>'helvetica',
'fontsize'=>8,
'stretchtext'=>4
),
'N'
)
);
$html = '';
$html .= '<tcpdf method="write1DBarcode" params="'.$params.'" />';
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->Output('my_file.pdf', 'I');
}

How to create same pdf file multiple time using tcpdf in codeigniter?

I'm using tcpdf library for pdf creation. I want to download same pdf multiple time(user will enter how many pdfs he want). I made a for loop which call pdf function according to the user entered value. The problem is code stop after creating first pdf. Following is my pdf function which I call multiple time. Also it take about 10-15 seconds to create pdf. Thanks!
public function generatePdf($eventId) {
$eventDetails = $this->events_model->getAttachment($eventId);
$image = $eventDetails[0]->image_source;
$startTime = $eventDetails[0]->startTime;
$regTime = $eventDetails[0]->regTime;
$locationName = $eventDetails[0]->location_name;
$location = $eventDetails[0]->location;
$date = strtotime($startTime);
$date1 = strtotime($regTime);
$dat = date('m/d/y', $date);
$tme = date('H:m', $date);
$regTme = date('m/d/ H:m', $date1);
$this->load->library('Pdf');
$pdf = new Pdf('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Event Ticket');
$pdf->SetTopMargin(0);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(true);
$pdf->setFooterMargin(0);
$pdf->setLeftMargin(0);
$pdf->setRightMargin(0);
$pdf->SetAutoPageBreak(true);
$pdf->SetAuthor('MPM');
$pdf->SetDisplayMode('real', 'default');
$pdf->AddPage();
$pdf->SetFont('Helvetica');
$pdf->SetFontSize('10');
$pdf->SetFont('', 'B');
$y = $pdf->getY();
$pdf->setCellPaddings(0, 1, 2, 1);
$pdf->SetFillColor(215, 235, 255);
$event_pic = './eventDocs/' . $image;
$logo_html = '<img width="196px;" height="700px;" src="' . base_url() . $event_pic . '" />';
$event_fixed_pic = './eventDocs/Untitled-2.png';
$event_fixed_pic_html = '<img height="200px;" src="' . base_url() . $event_fixed_pic . '" />';
$event_bottom_pic = './eventDocs/Untitled-4447.png';
$event_bottom_pic_html = '<img width="595px;" height="146px;" src="' . base_url() . $event_bottom_pic . '" />';
$pdf->writeHTMLCell(80, 280, '', $y, $logo_html, 0, 0, 0, false, '', true);
$pdf->setCellPaddings(60, 1, 2, 1);
$pdf->SetFont('', 'B', 14);
$pdf->SetTextColor(195, 195, 176);
$pdf->MultiCell(130, 5, $startTime, 0, false, 0, 0, '', '', true);
$pdf->Ln(25);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->SetFont('', 'B', 15);
$pdf->SetTextColor(0, 0, 0);
$pdf->MultiCell(140, 5, utf8_to_german($this->lang->line("event_pdf_top_heading1")), 0, false, 0, 0, '', '', true);
$pdf->Ln(6);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->MultiCell(170, 5, utf8_to_german($this->lang->line("event_pdf_top_heading2")), 0, false, 0, 0, '', '', true);
$linestyle = array('width' => 1.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(195, 195, 176));
$pdf->Line(75, 40, 149, 40, $linestyle);
$pdf->SetLineStyle(array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Ln(18);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->SetFont('', 'B', 11);
$pdf->SetTextColor(0, 0, 0);
$pdf->MultiCell(150, 5, utf8_to_german($this->lang->line("event_pdf_heading1")), 0, false, 0, 0, '', '', true);
$pdf->Ln(8);
$pdf->setCellPaddings(75, 0, 2, 1);
$pdf->MultiCell(200, 5, utf8_to_german($this->lang->line("event_pdf_heading2")), 0, false, 0, 0, '', '', true);
$pdf->Ln(38);
$pdf->setCellPaddings(5, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->SetFillColor(199, 195, 176);
$pdf->writeHTMLCell(60, 43, 0, 95, $locationName . '<br>' . $location, 0, 0, 1, false, '', true);
$pdf->Ln(140);
$pdf->setCellMargins(140, 95);
$pdf->writeHTMLCell('', 30, '', $y, $event_fixed_pic_html, 0, 0, 0, false, '', true);
$pdf->Ln(60);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(100, 5, utf8_to_german($this->lang->line("event_pdf_heading3")), 0, false, 0, 0, '', '', true);
$linestyle = array('width' => 1.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(195, 195, 176));
$pdf->Line(75, 163, 146, 163, $linestyle);
$pdf->SetLineStyle(array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->Ln(11);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->SetFont('', '', 10);
$pdf->SetTextColor(0, 0, 0);
$pdf->MultiCell(120, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para1")), 0, false, 0, 0, '', '', true);
$pdf->Ln(35);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(120, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para2")), 0, false, 0, 0, '', '', true);
$pdf->Ln(10);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(120, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para3")), 0, false, 0, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 0, 2, 1);
$pdf->setCellMargins(75);
$pdf->MultiCell(100, 5, utf8_to_german($this->lang->line("event_pdf_heading3_para4")), 0, false, 0, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellMargins(0, 240);
$pdf->writeHTMLCell(500, 52, '', $y, $event_bottom_pic_html, 0, 0, 1, false, '', true);
$pdf->SetFont('', '', 12);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 15, 2, 1);
$pdf->setCellMargins(10);
$pdf->MultiCell(50, 30, $locationName . ' ' . $location, 0, false, 1, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 10, 2, 1);
$pdf->setCellMargins(70);
$pdf->MultiCell(50, 10, $dat, 0, false, 1, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 13, 2, 1);
$pdf->setCellMargins(70);
$pdf->MultiCell(50, 10, utf8_to_german($this->lang->line("event_pdf_footer_para3")) . $regTme . $this->lang->line("event_pdf_footer_time"), 0, false, 1, 0, '', '', true);
$pdf->Ln(5);
$pdf->setCellPaddings(0, 18, 2, 1);
$pdf->setCellMargins(70);
$pdf->MultiCell(50, 10, utf8_to_german($this->lang->line("event_pdf_footer_para4")) . $tme . $this->lang->line("event_pdf_footer_time"), 0, false, 1, 0, '', '', true);
ob_end_clean();
$pdf->Output('pdfexample.pdf', 'D');
$pdf->Output('pdfexample1.pdf', 'D');
return 1;
}

Passing data from model to print into tcpdf in codeigniter

I'm trying to create a pdf file with some data in that I get from a query, the pdf creator is in the controller (TCPDF).
My storyboard :
I am using codeigniter to develop my php application. In my view, there is a table that every row have a button to create a pdf from information its row. I can preview it in modal bootstrap.
Now , I am confused how to passed that information to pdf (TCPDF).
Should i using GET or somrthing like that in my Controller ?
Or in modal ?
This is my view
<tbody>
<?php
$no = 1;
foreach($data_request as $data) {
?>
<tr>
<td class="center"><?php echo $no++.". ";?> </td>
<td class="sorting1"><?php echo $data['id_request'];?> </td>
<td class="center"><?php echo "$name"; ?></td>
<td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['time_start']));?></td>
<td class="center"><?php echo $data['keluhan'];?></td>
<td class="center"><span class="label label-warning"><?php echo $data['status_request'];?></span></td>
<td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['close_request']));?></td> <td class="center">
<a class="btn btn-danger" href="#">
<i class="halflings-icon white trash"></i> Close
</a>
<a class="btn btn-success" href="#" id="print" req_id="<?php echo $data['id_request']; ?>">
<i class="halflings-icon pencil"></i> Print
</a>
</td>
</tr>
<?php } ?>
</tbody>
//This is my modal bootstrap preview :
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1>Print Preview</h1>
</div>
<div class="modal-body">
<p id="id_preview"> </p>
</div>
<div class="modal-footer">
<?php $id= $data['id_request'];?>
Jadikan PDF
Close
</div>
</div>
This is my controller
public function generate_pdf($idRequest){
$this->model_request->selectOneRequest($idRequest);
$this->load->library("TC_PDF");
$pdf = new TC_Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Dzil');
$pdf->SetTitle('Form Perbaikan / Permintaan');
$pdf->SetSubject('TMS/DEPT/IT/06');
$pdf->SetKeywords('TCPDF, PDF, form, perbaikan, Permintaan');
// 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('helvetica', '', 12);
// add a page
$pdf->AddPage();
$pdf->Ln(8);
$pdf->Cell(30, 5, 'Nama', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 5, '$data_pdf[nama]', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 5, 'Departement', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 5, '', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 5, 'NIK', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 5, '', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Ln(4);
$pdf->Cell(30, 5, 'Permintaan / ', 0, 1, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 5, 'Perbaikan ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$html = <<<EOD
<form action="">
<input type="checkbox" name="request[]" id="Login" value="Login" > Login
<input type="checkbox" name="request[]" id="Login" value="Login" > Printer
<input type="checkbox" name="request[]" id="Login" value="Login" > Monitor
<input type="checkbox" name="request[]" id="Login" value="Login" > Computer
<input type="checkbox" name="request[]" id="Login" value="Login" > Network
<input type="checkbox" name="request[]" id="Login" value="Login" > Lain-lain
</form>
EOD;
$pdf->writeHTML($html, true, 1, false, 1);
$pdf->Ln(4);
$pdf->Cell(30, 10, 'Keluhan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 90,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(30, 10, 'Keterangan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 60,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(30, 10, 'Catatan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
$pdf->Cell( 0, 10,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Ln(4);
$pdf->SetFont('helvetica', '', 8);
$pdf->Cell(30, 5, 'Tgl Permintaan / Paraf', 1, 0, 'C', 0, '', 0, false, 'T', 'C'); //width, height,
$pdf->Cell(30, 5, 'Persetujuan Manajer', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Tgl Persetujuan', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Diterima Oleh', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Tgl Terima', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Perkiraan Selesai', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(25, 5, 'Tgl Selesai', 1, 1, 'C', 0, '', 0, false, 'T', 'C');
$pdf->Cell(30, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T'); //width, height,
$pdf->Cell(30, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Cell(25, 25, '', 1, 1, 'L', 0, '', 0, false, 'T', 'T');
$pdf->Ln(2);
$pdf->SetFont('helvetica', '', 8);
$pdf->Cell(0, 0, 'TMS-IT-06 (10.2001)', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_057.pdf', 'I');
}
This is my model
public function selectOneRequest($id_request){
$query = $this->db->get_where('tbl_request', array('id_request'=>$id_request));
return $query->result_array();
}
Just construct the href of the link to point to the generate_pdf function.. assuming your controller name is Tcpdf
Print

Declare variable outside class and access in method php [duplicate]

This question already has answers here:
Accessing variables and methods outside of class definitions
(6 answers)
Closed 12 months ago.
I use Codeigniter to build something. But I have problem when I tried to build module print. I want to use variable that sent from my controller. see my controller script below
public function print_data()
{
$this->load->library('Pdf');
$config = $this->config->item('basmalah');
$data['config'] = $config; //will send data to view
$this->load->view('/print_laporan_cashdraw',$data);
}
And my view like this
// print_r($config);exit;
$conf = $config;
class MYPDF extends TCPDF {
//Page header
public function Header() {
$this->SetFont('helvetica', '', 12);
$this->Write(0, 'PT. BASMALAH SIDOGIRI - '.$conf['bas_branch_name'], '', 0, 'C', true, 0, false, false, 0);
$this->Write(0, $conf['bas_branch_address'], '', 0, 'C', true, 0, false, false, 0);
// $this->Cell(0, 15, 'PT. BASMALAH SIDOGIRI', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '0', 'phase' => 10, 'color' => array(0, 0, 0));
$this->Line(10, 24, 200, 24, $style);
}
}
i have checked with print_r function its containt data, but i can't access variable
$config
in method Header. What should I do?
class MYPDF extends TCPDF {
//Page header
public function Header() {
// you have to do this to use global variable.
global $conf;
$this->SetFont('helvetica', '', 12);
$this->Write(0, 'PT. BASMALAH SIDOGIRI - '.$conf['bas_branch_name'], '', 0, 'C', true, 0, false, false, 0);
$this->Write(0, $conf['bas_branch_address'], '', 0, 'C', true, 0, false, false, 0);
// $this->Cell(0, 15, 'PT. BASMALAH SIDOGIRI', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '0', 'phase' => 10, 'color' => array(0, 0, 0));
$this->Line(10, 24, 200, 24, $style);
}
}
Use Following code
<?php
$conf = $config;
class MYPDF extends TCPDF {
public $conf = array();
public function setData($conf){
$this->conf = $conf;
}
//Page header
public function Header() {
$this->SetFont('helvetica', '', 12);
$this->Write(0, 'PT. BASMALAH SIDOGIRI - '.$this->conf['bas_branch_name'], '', 0, 'C', true, 0, false, false, 0);
$this->Write(0, $this->conf['bas_branch_address'], '', 0, 'C', true, 0, false, false, 0);
// $this->Cell(0, 15, 'PT. BASMALAH SIDOGIRI', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '0', 'phase' => 10, 'color' => array(0, 0, 0));
$this->Line(10, 24, 200, 24, $style);
}
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setData($conf);
?>

Categories