Make text fit in a cell with fpdf - php

im making a pdf file using fpdf.. The fdf generated will show data in table form from the database. My problem is, when the data string is too long, it do not fit well in the table cell. Look below in column no 3:
Below is my full code:
<?php
require('fpdf17/fpdf.php');
require('db.php');
//create a FPDF object
$pdf=new FPDF();
$pdf->SetFont('Times','B',20); //set font for the whole page (font family, style, size)
$pdf->SetTextColor(0,0,0); //using RGB value
//set up a page
$pdf->AddPage('P'); //potrait orientation
$pdf->SetDisplayMode('default'); //using 100 percent zoom and the viewer's default layout
$icon = "files/icon.png";
$pdf->Cell (10);
$pdf->Cell(60, 60, $pdf->Image($icon, $pdf->GetX(), $pdf->GetY(), 33.78), 0, 0, 'L', false);
$pdf->SetFillColor(0,0,0);
$pdf->SetFont('Times', '', 12);
$pdf->SetXY(10, 30);
$pdf->Cell(10);
$pdf->Cell(30, 6, 'Retrieval Date' , 0, 0, '', 0);
date_default_timezone_set("Asia/Kuala_Lumpur"); //set default time zone
$pdf->Cell(30, 6, ': '.date("d/m/Y"), 0, 2, 'B', 0);
//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY(20,40); //setting the position
$pdf->SetFont('Times', 'BU', 14);
$pdf->Write(12,'Absenteeism record for:');
$course_course_code = addslashes( filter_input( INPUT_GET,'course',FILTER_SANITIZE_STRING ) );
$data = "SELECT course_code, course_name FROM studentattendance
INNER JOIN course ON studentattendance.course_course_code=course.course_code WHERE course_course_code LIKE '$_GET[course]' GROUP BY course_code";
$result = $conn->query($data) or die("Error: ".mysqli_error($conn));
while($ser=mysqli_fetch_array($result)){
$course_code = $ser['course_code'];
$course_name = $ser['course_name'];
$pdf->SetFillColor(0,0,0);
$pdf->SetFont('Times', '', 12);
$pdf->SetY(50);
$pdf->Cell(10);
$pdf->SetX(20);
$pdf->Cell(30, 6, 'COURSE' , 0, 0, '', 0);
$pdf->Cell(30, 6, ': '.$course_code. ' - '.$course_name, 0, 2, 'B', 0);
}
//start first table
$pdf->SetFillColor(255,255,255);
$pdf->SetFont('Times', 'B', 12);
$pdf->SetXY(21,58);
$pdf->Cell(10, 6, 'No.', 1, 0, 'L', 1);
$pdf->Cell(25, 6, 'Matric no', 1, 0, 'L', 1);
$pdf->Cell(75, 6, 'Name', 1, 0, 'L', 1);
$pdf->Cell(25, 6, 'GROUP', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'Absenteeism %', 1, 0, 'L', 1);
$row_height = 6;
$y1_axis = 58;
$y1_axis = $y1_axis + $row_height;
$counter = 1;
$course_course_code = addslashes( filter_input( INPUT_GET,'course',FILTER_SANITIZE_STRING ) );
$data = "SELECT stud_matric, stud_name, group_group_code, getid,
SUM(studAtt_endTime - studAtt_startTime)/(course_contacthour_perWeek * 14) AS 'sum' FROM studentattendance
INNER JOIN course ON studentattendance.course_course_code=course.course_code
INNER JOIN student ON studentattendance.student_stud_matric=student.stud_matric
WHERE studAtt_status='0' AND course_course_code LIKE '$_GET[course]' GROUP BY getid ORDER BY sum DESC";
$result = $conn->query($data) or die("Error: ".mysqli_error($conn));
while($ser=mysqli_fetch_array($result)){
$stud_matric = $ser['stud_matric'];
$stud_name = $ser['stud_name'];
$group_group_code = $ser['group_group_code'];
$per=number_format($ser['sum'] * 100, 2)." %";
$pdf->SetFont('Times', '', 12);
$pdf->SetXY(21, $y1_axis);
$pdf->Cell(10, 6, $counter, 1, 0, 'L', 1);
$pdf->Cell(25, 6, $stud_matric, 1, 0, 'L', 1);
$pdf->Cell(75, 6, $stud_name, 1, 0, 'L', 1);
$pdf->Cell(25, 6, $group_group_code, 1, 0, 'L', 1);
$pdf->Cell(30, 6, $per, 1, 0, 'L', 1);
$pdf->Ln();
$y1_axis = $y1_axis + $row_height;
$counter++;
if ($counter % 34 === 0) {
$pdf->AddPage();
$y1_axis = 20;
}
}
//end first table
//Output the document
$pdf->Output("$course_code.pdf",'I');
?>
Please help me..

Change the size of the cell
$pdf->Cell(5, 6, 'No.', 1, 0, 'L', 1);
$pdf->Cell(25, 6, 'Matric no', 1, 0, 'L', 1);
$pdf->Cell(100, 6, 'Name', 1, 0, 'L', 1);
$pdf->Cell(25, 6, 'GROUP', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'Absenteeism %', 1, 0, 'L', 1);

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');
?>

How to auto adjust cell height in fpdf

How can I auto adjust the cell height in fpdf?
My pdf looks a little bit bad ;)
Screenshot of PDF
My code:
$pdf->SetFont('Arial', 'B', 13);
$pdf->SetLeftMargin(30);
$pdf->SetFillColor(193,229,252);
$pdf->Cell(15, 20, '', 0, 1, 'C');
$pdf->Cell($width_cell[0], 10, 'Datum', 1, 0, 'C', true);
$pdf->Cell($width_cell[1], 10, 'Von', 1, 0, 'C', true);
$pdf->Cell($width_cell[2], 10, 'Bis', 1, 0, 'C', true);
$pdf->Cell($width_cell[3], 10, 'Grund', 1, 1, 'C', true);
$pdf->SetFont('Arial', '', 13);
$fill = false;
while ($z = $stmt->fetch(PDO::FETCH_ASSOC)) {
$pdf->Cell($width_cell[0],10,date("d.m.Y", strtotime($z['date'])),1,0,'C',$fill);
$pdf->Cell($width_cell[1],10,substr($z['startTime'], 0, 5) . ' Uhr',1,0,'C',$fill);
$pdf->Cell($width_cell[2],10,substr($z['endTime'], 0, 5) . ' Uhr',1,0,'C',$fill);
$pdf->Cell($width_cell[3],10,$z['reason'],1,1,'C',$fill);
}
$pdf->Output();
To output multiple lines into a cell you'll need to use MultiCell instead of Cell.

How to use two color in one TCPDF Cell?

I have an invoice template. i used Cell for showing text into box.
here is my code:
$ntitle = 'No:';
$factornum = '1898';
$startheader = 15;
$pdf->SetXY($startheader, 4);
$pdf->Cell(50, 0, 'Date: '.date("Y-m-d"), 1, 1, 'C', 0, '', 1);
$pdf->SetXY($startheader, 12);
$pdf->SetTextColor(255, 0, 0);
$pdf->Cell(50, 0, $ntitle . $factornum, 1, 1, 'C', 0, '', 1);
$pdf->SetTextColor(0, 0, 0);
I want to use two text color in second cell.
$ntitle should be echo in black and $factornum in red
For example, output must be like:
No: (with black color) 1898 (with red color)
How can I do this in TCPDF?
I checked TCPDF examples. but I did not get any results
$ntitle = 'No:';
$factornum = '1898';
$startheader = 15;
$pdf->AddPage();
$pdf->SetXY($startheader, 4);
$pdf->Cell(50, 0, 'Date: '.date("Y-m-d"), 1, 1, 'C', 0, '', 1);
$pdf->SetXY($startheader, 12);
$pdf->SetTextColor(255, 0, 0);
//$pdf->Cell(50, 0, $ntitle . $factornum, 1, 1, 'C', 0, '', 1);
$pdf->SetFillColor(255, 255, 255);
$pdf->writeHTMLCell(50, '', '', '', '<span style="color:#000">'.$ntitle.'</span>' . $factornum, 1, 1, 'C', 0, '', 1);
$pdf->SetTextColor(0, 0, 0);

FPDF Multiply Table PHP PDO

I need to print the curriculum data's in PDF file. On the Front-End got no problem.
But applying the same code on FPDF is kinda hard for me. I need to display the curriculum data's like on my front-end. I made this so far.
And here is the whole code for that script.
<?php
include "../../include/student_session.php";
$user_id = $_SESSION['student'];
$stmt = $DB_con->prepare("SELECT *, h.campus as 'h.campus', k.batch as 'k.batch', j.id as 'j.id', a.department_id as 'dept' FROM student_info a
INNER JOIN section b ON b.id = a.section_id
INNER JOIN course c ON c.id = a.course_id
INNER JOIN year_tbl d ON d.id = a.year_id
INNER JOIN batch_tbl e ON e.id = a.batch_id
INNER JOIN department f ON f.id = a.department_id
INNER JOIN scholarship g ON g.id = a.scholarship_id
INNER JOIN campus h ON h.id = a.campus
INNER JOIN school_year i ON i.id = a.sy_id
INNER JOIN curriculum j ON j.department_id = a.department_id AND j.course_id = a.course_id
INNER JOIN batch_tbl k ON k.id = j.batch_id
WHERE a.id=:id");
$stmt->execute(array(":id"=>$user_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
require('fpdf.php');
class PDF extends FPDF {
function Header() {
// Logo
$this->Image('../../login-folder/assets/img/logo_ac_long.png',68,10,80);
}
function Footer() {
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
//$this->Line(20, 45, 210-20, 45); // 20mm from each edge
$this->GetY(15);
$x=$this->GetY(15);
//$this->Line(160,250,296-100,250);
$this->Line(10,285,200,285);
$this->Ln();
$fech = time();
$fecha = date( "m/d/y" ,$fech);
$this->Text(10,288,$fecha);
}
}
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$pdf->Ln(30);
$pdf->Cell(10);
$pdf->SetFont('Arial','', 8);
$pdf->Cell(30,5,'Student Number: '.$userRow['student_no']);
$pdf->Cell(70);
$pdf->Cell(30,5,'Section Block : '.$userRow['section_code']);
$pdf->Ln(6);
$pdf->Cell(10);
$pdf->Cell(30,5,'Reference No : ----------');
$pdf->Cell(70);
$pdf->Cell(30,5,'School Year : '.$userRow['school_year']);
$pdf->Ln(6);
$pdf->Cell(10);
$pdf->Cell(30,5,'Name : '.$userRow['student_name']);
$pdf->Cell(70);
$pdf->Cell(30,5,'Semester : '.$userRow['semester']);
$pdf->Ln(6);
$pdf->Cell(10);
$pdf->Cell(30,5,'Course : '.$userRow['course_code']);
$pdf->Cell(70);
$pdf->Cell(30,5,'Year : '.$userRow['year']);
$pdf->Ln(6);
$pdf->Cell(10);
$pdf->Cell(30,5,'Curriculum : Ver.'.$userRow['j.id'].', '.$userRow['k.batch']);
$pdf->Cell(70);
$pdf->Cell(30,5,'Status : Currently Enrolled');
$pdf->Ln(6);
$pdf->Cell(10);
$pdf->Cell(30,5,'Campus : '.$userRow['campus']);
$pdf->Cell(70);
$pdf->Cell(30,5,'Scholarship : '.$userRow['scholarship_type']);
$stmt5 = $DB_con->prepare("SELECT *,a.id as 'a.id', b.year_id as 'b.year_id' FROM year_tbl a INNER JOIN subjects b ON b.year_id = a.id AND department_id = :dept group by a.id order by a.id asc; ");
$stmt5->bindparam(":dept", $userRow['dept']);
$stmt5->execute();
$userRow5=$stmt5->fetchAll(PDO::FETCH_ASSOC);
if($stmt5->rowCount() > 0) {
foreach ($userRow5 as $key) {
$pdf->Ln(10);
$pdf->Cell(10);
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(30,5,$key['year']. ' - ' .$key['semester']);
//set initial y axis position per page
$y_axis_initial = 86;
//Set Row Height
$row_height = 6;
//print column titles for the actual page
$pdf->SetFillColor(255, 255, 255);
$pdf->SetFont('Arial', '', 8);
$pdf->SetY($y_axis_initial);
$pdf->SetX(12);
$pdf->Cell(30, 6, 'Subject Code', 1, 0, 'C', 1);
$pdf->Cell(10, 6, 'Units', 1, 0, 'C', 1);
$pdf->Cell(12, 6, 'Prelims', 1, 0, 'C', 1);
$pdf->Cell(14, 6, 'Remarks', 1, 0, 'C', 1);
$pdf->Cell(12, 6, 'Midterm', 1, 0, 'C', 1);
$pdf->Cell(14, 6, 'Remarks', 1, 0, 'C', 1);
$pdf->Cell(12, 6, 'Finals', 1, 0, 'C', 1);
$pdf->Cell(14, 6, 'Remarks', 1, 0, 'C', 1);
$pdf->Cell(12, 6, 'Average', 1, 0, 'C', 1);
$pdf->Cell(14, 6, 'Equivalent', 1, 0, 'C', 1);
$pdf->Cell(40, 6, 'Instructor', 1, 0, 'C', 1);
$y_axis = $y_axis_initial + $row_height;
//initialize counter
$i = 0;
//Set maximum rows per page
$max = 25;
$stmt2 = $DB_con->prepare("SELECT *, d.id as 'b.section_id', c.id as 'b.subject_id', c.subject_code as 'c.subject_code', a.year_id as 'yid', a.batch_id as 'bid', (lec_units + lab_units) as 'total' FROM student_info a
INNER JOIN curriculum b ON b.department_id = a.department_id AND b.batch_id = a.batch_id AND b.course_id = a.course_id
INNER JOIN curriculum_subjects f ON f.curriculum_id = b.id
INNER JOIN subjects c ON c.id = f.subject_id AND c.year_id = :yid
INNER JOIN section d ON d.id = a.section_id
INNER JOIN batch_tbl e ON e.id = a.batch_id
WHERE a.student_no = :value");
$stmt2->bindparam(":value", $userRow['student_no']);
$stmt2->bindparam(":yid", $key['a.id']);
$stmt2->execute();
$userRow2=$stmt2->fetchAll(PDO::FETCH_ASSOC);
if ($stmt2->rowCount() > 0) {
foreach ($userRow2 as $key2) {
if ($i == $max) {
$pdf->AddPage();
//print column titles for the current page
$pdf->SetY($y_axis_initial);
$pdf->SetX(33);
//$pdf->Cell(30, 6, 'Resident', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Subject Code')+3, 6, 'Subject Code', 1, 0, 'C', 1);
$pdf->Cell($pdf->GetStringWidth('Units')+3, 6, 'Units', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Prelims')+3, 6, 'Prelims', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Remarks')+3, 6, 'Remarks', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Midterm')+3, 6, 'Midterm', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Remarks')+3, 6, 'Remarks', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Finals')+3, 6, 'Finals', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Remarks')+3, 6, 'Remarks', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Average')+3, 6, 'Average', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Equivalent')+3, 6, 'Equivalent', 1, 0, 'L', 1);
$pdf->Cell($pdf->GetStringWidth('Instructor')+3, 6, 'Instructor', 1, 0, 'L', 1);
//Go to next row
$y_axis = $y_axis + $row_height;
//Set $i variable to 0 (first row)
$i = 0;
}
$semester = $key2['subject_code'];
$pdf->SetY($y_axis);
$pdf->SetX(12);
$pdf->Cell(30, 6, $semester, 1, 0, 'C', 1);
$pdf->Cell(10, 6, '', 1, 0, 'C', 1);
$pdf->Cell(12, 6, '', 1, 0, 'C', 1);
$pdf->Cell(14, 6, '', 1, 0, 'C', 1);
$pdf->Cell(12, 6, '', 1, 0, 'C', 1);
$pdf->Cell(14, 6, '', 1, 0, 'C', 1);
$pdf->Cell(12, 6, '', 1, 0, 'C', 1);
$pdf->Cell(14, 6, '', 1, 0, 'C', 1);
$pdf->Cell(12, 6, '', 1, 0, 'C', 1);
$pdf->Cell(14, 6, '', 1, 0, 'C', 1);
$pdf->Cell(40, 6, '', 1, 0, 'C', 1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
$pdf->Output();
}
}
// $pdf->Ln(10);
// $pdf->Cell(10);
// $pdf->SetFont('Arial','b', 8);
// $pdf->Cell(30,5,'NOTE: THIS IS NOT VALID WHEN THERE IS NO SIGNATURE OF REGISTAR OFFICE.');
}
?>
What mistake did I do here? What I'm missing? I need help to achieve the front-end output like that.

Add sub-headers in all pages with FPDF

I have a simple script that generates a PDF file. I'm getting the info I need from the database and using a foreach to create the pages of the PDF file, and the last page I have some charts and other info that are not retrived from DB. All the pages, except this last one, must have a subheader.
My current code is:
foreach ($sql as $key => $value)
{
$pdf->Cell(20, $line_height, $value['sale_id'], '', '', 'L');
$pdf->Cell(90, $line_height, $value['product'], '', '', 'L');
$pdf->Cell(90, $line_height, $value['ammount'], '', '', 'L');
$pdf->Cell(90, $line_height, $value['value'], '', '', 'L');
}
Basically, I need to have the subheader describing each row. But If I do this, all the lines will have the subheader:
foreach ($sql as $key => $value)
{
$pdf->SetFont('Arial', 'B', $font_size);
$pdf->Ln(2 * $line_height);
$pdf->Cell(20, $line_height, 'Number', '', '', 'L');
$pdf->Cell(120, $line_height, 'Product', '', '', 'L');
$pdf->Cell(40, $line_height, 'Ammount', '', '', 'L');
$pdf->Cell(40, $line_height, 'Value ($)', '', '', 'L');
//
$pdf->SetFont('Arial', 'B', $font_size);
$pdf->Ln(2 * $line_height);
$pdf->Cell(20, $line_height, $value['sale_id'], '', '', 'L');
$pdf->Cell(120, $line_height, $value['product'], '', '', 'L');
$pdf->Cell(40, $line_height, $value['ammount'], '', '', 'L');
$pdf->Cell(40, $line_height, $value['value'], '', '', 'L');
}
I need this subheader in each page, except the last one. I've tried to do some crazy code with pageNo() function, but it didn't work.
Thank's!
Ok guys, I solved my problem. For anyone who's looking for something similar, here is what I did: The GetY() function return the Y position of that line, so when it's the first line of the page, this value will be 0 (or a constant, depends of your layout). I just did:
foreach ($sql as $key => $value)
{
if ($pdf->GetY() == 0)
{
$pdf->SetFont('Arial', 'B', $font_size);
$pdf->Ln(2 * $line_height);
$pdf->Cell(20, $line_height, 'Number', '', '', 'L');
$pdf->Cell(120, $line_height, 'Product', '', '', 'L');
$pdf->Cell(40, $line_height, 'Ammount', '', '', 'L');
$pdf->Cell(40, $line_height, 'Value ($)', '', '', 'L');
}
$pdf->SetFont('Arial', 'B', $font_size);
$pdf->Ln(2 * $line_height);
$pdf->Cell(20, $line_height, $value['sale_id'], '', '', 'L');
$pdf->Cell(120, $line_height, $value['product'], '', '', 'L');
$pdf->Cell(40, $line_height, $value['ammount'], '', '', 'L');
$pdf->Cell(40, $line_height, $value['value'], '', '', 'L');
}
Thank you all!
override the method header() of FPDF in your class.
class PDF extends FPDF
{
public function Header() {
$this->Cell(0, 8, "HEADER TEXT", 0, 0, 'R');
}
}
This method will be called automatically by the FPDF while adding a new page.
I had this same problem trying to get a header on each page. This also connects to a MySql database. Here is what ended up working for me.
<?php
//PDF USING MULTIPLE PAGES
//FILE Originally CREATED BY: Carlos José Vásquez Sáez
//I fixed this on May 3/2013 as it was not working correctly for me.
define('FPDF_FONTPATH', '/font/');
require('fpdf.php');
//Connect to your database
$link = mysql_connect("localhost","","") or die ('Could not select database.');
$db_select = mysql_select_db("", $link) or die ('Could not select database.');
//Create new pdf file
$pdf=new FPDF();
//Open file
$pdf->Open();
//Disable automatic page break
$pdf->SetAutoPageBreak(false);
//Add first page
$pdf->AddPage();
//set initial y axis position per page
$y_axis_initial = 10;
//Set Row Height
$row_height = 8;
//print column titles for the actual page
$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial', 'B', 11);
$pdf->SetY($y_axis_initial);
$pdf->SetX(10);
$pdf->Cell(80, $row_height, 'Products', 1, 0, 'C', 1);
$pdf->Cell(20, $row_height, 'Price', 1, 0, 'C', 1);
$pdf->Cell(30, $row_height, 'Customer', 1, 0, 'C', 1);
//Select the Products you want to show in your PDF file
$result=mysql_query('SELECT Product,Price,Customer FROM your_table ORDER BY Product', $link);
//initialize counter
$i = 0;
//Set maximum rows per page
$max = 30;
//Data Table y axis position starting point
$y_axis = $y_axis_initial + $row_height;
while($row = mysql_fetch_array($result))
{
//If the current row is the last one, create new page and print column title
if ($i == $max)
{
$pdf->AddPage();
//print column titles for the current page
$pdf->SetY($y_axis_initial);
$pdf->SetX(10);
$pdf->Cell(80, $row_height, 'Product', 1, 0, 'C', 1);
$pdf->Cell(20, $row_height, 'Price', 1, 0, 'C', 1);
$pdf->Cell(30, $row_height, 'Customer', 1, 0, 'C', 1);
//Set $i variable to 0 (first row)
$i = 0;
//Reset the y axis value
$y_axis = $y_axis_initial + $row_height;;
}
$Product = $row['Product'];
$Price = $row['Price'];
$Cust = $row['Customer'];
$pdf->SetY($y_axis);
$pdf->SetX(10);
$pdf->Cell(80, $row_height, $Product, 1, 0, 'L', 1);
$pdf->Cell(20, $row_height, $Price, 1, 0, 'L', 1);
$pdf->Cell(30, $row_height, $Cust, 1, 0, 'L', 1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}
mysql_close($link);
//Create file
$pdf->Output();

Categories