Passing data from model to print into tcpdf in codeigniter - php
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
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'); ?>
TCPDF image not showed on refresh when I use it with writehtml()
I am creating an invoice with TCPDF (I need UTF-8). When I add an image using the function WriteHTML(), the image is only available on the first load. When I refresh the site, the image is removed from the server. When I am using it without writeHTML(), everything is good. Where is the problem? I am using html to create a table for products in invoice. Thanks <?php $dodavatel = "adress"; $fakturacniAdresa = "address2"; $fakturacniICDIC = "ezh hfgj hfgjhj f"; $dtVystaveni = "22.03.2018"; $dtZdanPlneni = "22.03.2018"; $dtSplatnosti = "22.03.2018"; $bankovniUcet = "acount number"; $varSymbol = "65464"; $specSymbol = "45454"; $kUhrade = "4 USD"; $iban = "CZ511111111111"; $swift = "XXXXXXXX"; require_once('../lib/tcpdf/tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->setFont('dejavusans'); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); // add a page $pdf->AddPage(); $pdf->Image('logo.jpg'); $pdf->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => 4, 'color' => array(255, 255, 255))); $pdf->SetFontSize(7); $pdf->setCellHeightRatio(1.5); $pdf->Cell(80, 0, "Dodavatel:", 1); $pdf->Cell(70, 0, "Fakturační adresa:", 1); $pdf->Ln(5); $pdf->MultiCell(80, 20, $dodavatel, 1, 'L', 0, 0); $pdf->MultiCell(70, 20, $fakturacniAdresa, 1, 'L', 0, 0); $pdf->MultiCell(39, 20, $fakturacniICDIC, 1, 'L', 0, 0); $pdf->Ln(); $pdf->Cell(30, 0, "Datum vystavení:", 1); $pdf->Cell(30, 0, $dtVystaveni, 1, 0, 'C'); $pdf->Cell(39, 0, "Datum zdan. plnění:", 1); $pdf->Cell(30, 0, $dtZdanPlneni, 1, 0, 'C'); $pdf->Cell(30, 0, "Datum splatnosti:", 1); $pdf->Cell(30, 0, $dtSplatnosti, 1, 0, 'C'); $pdf->Ln(15); $pdf->SetFillColor(119, 207, 240); $pdf->SetTextColor(255, 255, 255); //bila $pdf->Cell(80, 7, "Bankovní účet", 1, 0, '', 1); $pdf->Cell(30, 7, "Var. symbol", 1, 0, '', 1); $pdf->Cell(45, 7, "Spec. symbol", 1, 0, '', 1); $pdf->Cell(34, 7, "K úhradě", 1, 0, 'R', 1); $pdf->Ln(); $pdf->Cell(80, 6, $bankovniUcet, 1, 0, '', 1); $pdf->Cell(30, 6, $varSymbol, 1, 0, '', 1); $pdf->Cell(45, 6, $specSymbol, 1, 0, '', 1); $pdf->Cell(34, 6, $kUhrade, 1, 0, 'R', 1); $pdf->Ln(); $pdf->Cell(20, 6, "IBAN:", 1, 0, '', 1); $pdf->Cell(169, 6, $iban, 1, 0, '', 1); $pdf->Ln(); $pdf->Cell(20, 6, "SWIFT:", 1, 0, '', 1); $pdf->Cell(169, 6, $swift, 1, 0, '', 1); $pdf->Ln(); $pdf->SetFillColor(255, 255, 255); //bila $pdf->SetTextColor(0, 0, 0); //cerna $pdf->Cell(189, 8, "Fakturujeme Vám za dodané zboží či služby:", 1); $pdf->Ln(10); $pdf->Ln(); $tbl = <<<EOD <style> td { border-bottom:0.1px solid gray; padding-top: 10px; } </style> <table> <thead> <tr> <td width="70mm"><b>Označení dodávky</b></td> <td width="10mm" align="center"><b>Počet</b></td> <td width="13mm" align="center"><b>Měna</b></td> <td width="22mm" align="center"><b>DPH %</b></td> <td width="22mm" align="center"><b>Bez DPH</b></td> <td width="22mm" align="center"><b>DPH</b></td> <td width="30mm" align="right"><b>Celkem</b></td> </tr> </thead> EOD; for ($i = 0; $i < 10; $i++) { $tbl .= <<<EOD <tr> <td width="70mm">Something</td> <td width="10mm" align="center">11</td> <td width="13mm" align="center">USD</td> <td width="22mm" align="center">21</td> <td width="22mm" align="center">290</td> <td width="22mm" align="center">60,9</td> <td width="30mm" align="right" style="background-color:#e4e4e4;"><b>359</b></td> </tr> EOD; } $tbl .= <<<EOD </table> EOD; $pdf->writeHTML($tbl, true, false, false, false, ''); $pdf->Ln(); $pdf->Cell(110, 6, "Razítko a podpis:", 1); $pdf->Cell(30, 6, "Základ", 1); $pdf->Cell(20, 6, "Výše DPH", 1); $pdf->Cell(29, 6, "Celkem", 1, 0, 'R', 1); $pdf->Ln(); $pdf->Output('invoice.pdf', 'I');
This is probably not the right way, but I solved it by commenting in the tcpdf.php file unlink($file); (line 7801). I don't know why it's there. If anyone finds a better solution, I'll be glad.
How to make table header and table footer appear on each page?
The table footer and header only appear at the beginning and at the end of the page. I'm using FPDF. This is the code: $pdf = new myPDF(); $pdf->AliasNbPages('{nb}'); $pdf->AddPage('L', 'A4', 0); $pdf->headerTable(); $pdf->viewTable($con); $pdf->footerTable(); $pdf->Output(); This is myPDF class: <?php $con = new PDO('mysql:host=localhost;dbname=db_tc', 'root', ''); require('function.php'); require('fpdf/fpdf.php'); class myPDF extends FPDF { function header() { $this->SetleftMargin(30); $this->SetFont('Times', 'B', 14); $this->Cell(0, 10, 'Office 1', 0, 0, 'C'); $this->Ln(20); } function footer() { $this->SetY(-15); $this->SetFont('Times', '', 8); $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C'); } function headerTable() { $this->SetleftMargin(20); $this->SetFillColor(255, 213, 31); $this->SetDrawColor(50, 50, 100); $this->SetFont('Times', 'B', 12); $this->Cell(15, 10, 'Nomor', 1, 0, 'C', true); $this->Cell(40, 10, 'Tanggal Cek', 1, 0, 'C', true); $this->Cell(40, 10, 'Type Unit', 1, 0, 'C', true); $this->Cell(40, 10, 'Serial Number', 1, 0, 'C', true); $this->Cell(40, 10, 'Serial Number2', 1, 0, 'C', true); $this->Cell(30, 10, 'Lokasi', 1, 0, 'C', true); $this->Cell(30, 10, 'Ruangan', 1, 0, 'C', true); $this->Ln(); } function footerTable() { $this->SetleftMargin(30); $this->SetFillColor(255, 213, 31); $this->SetDrawColor(50, 50, 100); $this->SetFont('Times', 'B', 12); $this->Cell(15, 10, 'Nomor', 1, 0, 'C', true); $this->Cell(40, 10, 'Tanggal Cek', 1, 0, 'C', true); $this->Cell(40, 10, 'Type Unit', 1, 0, 'C', true); $this->Cell(40, 10, 'Serial Number', 1, 0, 'C', true); $this->Cell(40, 10, 'Serial Number2', 1, 0, 'C', true); $this->Cell(30, 10, 'Lokasi', 1, 0, 'C', true); $this->Cell(30, 10, 'Ruangan', 1, 0, 'C', true); $this->Ln(); } function viewTable($con) { $this->SetleftMargin(30); $this->SetFont('Times', '', 12); $this->SetFillColor(224, 224, 224); $stmt = $con->query("SELECT * FROM officepakai"); while ($data = $stmt->fetch(PDO::FETCH_OBJ)) { $this->Cell(15, 10, $data->Nomor, 1, 0, 'C', true); $this->Cell(40, 10, $data->Tanggal_Cek, 1, 0, 'L', true); $this->Cell(40, 10, $data->Type_Unit, 1, 0, 'L', true); $this->Cell(40, 10, $data->Serial_Number, 1, 0, 'L', true); $this->Cell(40, 10, $data->Serial_Number2, 1, 0, 'L', true); $this->Cell(30, 10, $data->Lokasi, 1, 0, 'L', true); $this->Cell(30, 10, $data->Ruangan, 1, 0, 'L', true); $this->Ln(); } } } $pdf = new myPDF(); $pdf->AliasNbPages('{nb}'); $pdf->AddPage('L', 'A4', 0); $pdf->headerTable(); $pdf->viewTable($con); $pdf->footerTable(); $pdf->Output(); ?>
I haven't worked with this lib but as per it's documentation here I'd say only Header and Footer methods are being called, but you seem to have some customizations called headerTable and footerTable. The Header() and Footer() methods are called automatically, so I believe that calling the custom methods inside them should do the trick: function Header() { $this->SetleftMargin(30); $this->SetFont('Times', 'B', 14); $this->Cell(0, 10, 'Office 1', 0, 0, 'C'); $this->Ln(20); $this->headerTable(); // add this } function Footer() { $this->SetY(-15); $this->SetFont('Times', '', 8); $this->Cell(0, 10, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'C'); $this->footerTable(); // add this }
How to show unique value on tcpdf?
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 }
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; }