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

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

class MYPDF extends TCPDF {
//Page header
public function Header() {
// you have to do this to use global variable.
global $conf;
$this->SetFont('helvetica', '', 12);
$this->Write(0, 'PT. BASMALAH SIDOGIRI - '.$conf['bas_branch_name'], '', 0, 'C', true, 0, false, false, 0);
$this->Write(0, $conf['bas_branch_address'], '', 0, 'C', true, 0, false, false, 0);
// $this->Cell(0, 15, 'PT. BASMALAH SIDOGIRI', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '0', 'phase' => 10, 'color' => array(0, 0, 0));
$this->Line(10, 24, 200, 24, $style);
}
}

Use Following code
<?php
$conf = $config;
class MYPDF extends TCPDF {
public $conf = array();
public function setData($conf){
$this->conf = $conf;
}
//Page header
public function Header() {
$this->SetFont('helvetica', '', 12);
$this->Write(0, 'PT. BASMALAH SIDOGIRI - '.$this->conf['bas_branch_name'], '', 0, 'C', true, 0, false, false, 0);
$this->Write(0, $this->conf['bas_branch_address'], '', 0, 'C', true, 0, false, false, 0);
// $this->Cell(0, 15, 'PT. BASMALAH SIDOGIRI', 0, false, 'C', 0, '', 0, false, 'M', 'M');
$style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '0', 'phase' => 10, 'color' => array(0, 0, 0));
$this->Line(10, 24, 200, 24, $style);
}
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setData($conf);
?>

Related

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
}

Output pdf not working on new server with TCPDF

I have a CRM for a couple of years working perfect with the TCPDF and I put in a new server and now I have some problems (the code is exactly the same in both of servers).
This is the code generating the PDF :
<?php
//Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
$id_facture = $_POST['id_facture'];
$id_client = $_POST['id_client'];
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = K_PATH_IMAGES.'logo.jpg';
$this->Image($image_file, 18, 5, 80, '', 'JPG', '', 'T', true, 300, '', false, false, 0, false, false, false);
}
// Page footer
public function Footer() {
$total = $this->getAliasNbPages();
//if($this->getAliasNumPage() == $total){
$info_bank = GET_bank_account();
if($bank['clearing'] != ''){$clearing = '<br>Clearing : '.$bank['clearing'];}
// Set font
$this->SetFont('helvetica', '', 8);
$txt_footer = '<table border="0" width="100%" cellpadding="2"><tr>
<td>'.NOM_SOCIETE.'<br>
'.ADRESSE_SOCIETE.' - '.CODE_POSTAL_SOCIETE.'-'.VILLE_SOCIETE.'</td>';
while($bank = mysqli_fetch_array($info_bank)){
$txt_footer .= '
<td>'.$bank['nom'].'<br>IBAN : '.$bank['iban'].'<br>BIC : '.$bank['bic'].'<br>'.$bank['type'].' : '.$bank['compte'].' '.$clearing.'
</td></tr>';
}
$txt_footer .= '<tr>
<td colspan="2" align="center"> '.MORE_INFO_SOCIETE.'</td>';
$txt_footer .= '</tr></table><hr>';
$txt_footer = ($txt_footer);
if($this->getNumPages() == 1){
$this->SetY(-30);
$this->SetFont('helvetica', 'B', 9);
$this->writeHTMLCell(0, 1, 15, $y_start, 'Informations bancaires', array('B' => array('width' => 0.4, 'cap' => 'butt', 'join' => 'round', 'dash' => 0, 'phase' => 1, 'color' => array(0, 0, 0))), 0, 0, true, 'J', true);
$this->Ln(5);
$this->SetFont('helvetica', '', 8);
$this->writeHTML($txt_footer, true, false, true, false, '');
}else{
if ($this->getPage() > 1){
$this->SetY(-30);
$this->SetFont('helvetica', 'B', 9);
$this->writeHTMLCell(0, 1, 15, $y_start, 'Informations bancaires', array('B' => array('width' => 0.4, 'cap' => 'butt', 'join' => 'round', 'dash' => 0, 'phase' => 1, 'color' => array(0, 0, 0))), 0, 0, true, 'J', true);
$this->Ln(5);
$this->SetFont('helvetica', '', 8);
$this->writeHTML($txt_footer, true, false, true, false, '');
//$this->Ln(5);
//$this->Cell(0, 5, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), '', false, 'R', 0, '', 0, false, 'T', 'M');
}else{
$this->SetY(-10);
$this->Cell(0, 5, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 'T', false, 'C', 0, '', 0, false, 'T', 'M');
}
}
//}
}
public function MultiRowIntervention($firstC, $secondC, $thirdC, $fourthC) {
$page_start = $this->getPage();
$y_start = $this->GetY();
// write the 1 cell
$this->MultiCell(25, 0, $firstC, 0, 'L', 0, 1, '', '', true, 'B', 0);
$page_end_1 = $this->getPage();
$y_end_1 = $this->GetY();
$this->setPage($page_start);
// write the 2 cell
$this->writeHTMLCell(130, 0, 35, $y_start, ($secondC), 0, 1, 0, 'L' );
$page_end_2 = $this->getPage();
$y_end_2 = $this->GetY();
$this->setPage($page_start);
// write the 3 cell
$this->MultiCell(25, 0, $thirdC, 0, 'L', 0, 1, 165 ,$y_start, true, 'B', 0);
$page_end_3 = $this->getPage();
$y_end_3 = $this->GetY();
$this->setPage($page_start);
// write the 4 cell
$this->MultiCell(20, 0, $fourthC, 0, 'R', 0, 1, 175 ,$y_start, true, 'B', 0);
$page_end_4 = $this->getPage();
$y_end_4 = $this->GetY();
// set the new row position by case
if (max($page_end_1,$page_end_2,$page_end_3,$page_end_4) == $page_start) {
$ynew = max($y_end_1, $y_end_2, $page_end_3, $page_end_4);
} elseif ($page_end_1 == $page_end_2) {
$ynew = max($y_end_1, $y_end_2);
} elseif ($page_end_2 == $page_end_3) {
$ynew = max($y_end_2, $y_end_3);
}elseif ($page_end_3 == $page_end_4) {
$ynew = max($y_end_3, $y_end_4);
} elseif ($page_end_1 > $page_end_2) {
$ynew = $y_end_1;
} elseif($page_end_2 > $page_end_3) {
$ynew = $y_end_2;
} elseif($page_end_3 > $page_end_4) {
$ynew = $y_end_3;
}else{
$ynew = $y_end_4;
}
$this->setPage(max($page_end_1,$page_end_2));
$this->SetXY($this->GetX(),$ynew);
}
public function MultiRowMateriel($firstC, $secondC, $thirdC, $fourthC, $fifthC) {
$page_start = $this->getPage();
$y_start = $this->GetY();
// write the 1 cell
$this->MultiCell(25, 0, $firstC, 0, 'L', 0, 1, '', '', true, 'B', 0);
$page_end_1 = $this->getPage();
$y_end_1 = $this->GetY();
$this->setPage($page_start);
// write the 2 cell
$this->writeHTMLCell(115, 0, 35, $y_start, ($secondC), 0, 1, 0, 'L' );
//$this->MultiCell(115, 0, ($secondC), 0, 'L', 0, 1, 35,$y_start, true, 'B', 0);
$page_end_2 = $this->getPage();
$y_end_2 = $this->GetY();
$this->setPage($page_start);
// write the 3 cell
$this->MultiCell(15, 0, $thirdC, 0, 'C', 0, 1, 150 ,$y_start, true, 'B', 0);
$page_end_3 = $this->getPage();
$y_end_3 = $this->GetY();
$this->setPage($page_start);
// write the 4 cell
$this->MultiCell(25, 0, $fourthC, 0, 'R', 0, 1, 153 ,$y_start, true, 'B', 0);
$page_end_4 = $this->getPage();
$y_end_4 = $this->GetY();
$this->setPage($page_start);
// write the 5 cell
$this->MultiCell(20, 0, $fifthC, 0, 'R', 0, 1, 175 ,$y_start, true, 'B', 0);
$page_end_5 = $this->getPage();
$y_end_5 = $this->GetY();
// set the new row position by case
if (max($page_end_1,$page_end_2,$page_end_3,$page_end_4,$page_end_5) == $page_start) {
$ynew = max($y_end_1, $y_end_2, $page_end_3, $page_end_4, $page_end_5);
} elseif ($page_end_1 == $page_end_2) {
$ynew = max($y_end_1, $y_end_2);
} elseif ($page_end_2 == $page_end_3) {
$ynew = max($y_end_2, $y_end_3);
}elseif ($page_end_3 == $page_end_4) {
$ynew = max($y_end_3, $y_end_4);
}elseif ($page_end_4 == $page_end_5) {
$ynew = max($y_end_4, $y_end_5);
} elseif ($page_end_1 > $page_end_2) {
$ynew = $y_end_1;
} elseif($page_end_2 > $page_end_3) {
$ynew = $y_end_2;
} elseif($page_end_3 > $page_end_4) {
$ynew = $y_end_3;
}elseif($page_end_4 > $page_end_5) {
$ynew = $y_end_4;
}else{
$ynew = $y_end_5;
}
$this->setPage(max($page_end_1,$page_end_2,$page_end_3,$page_end_4,$page_end_5));
$this->SetXY($this->GetX(),$ynew);
}
public function MultiRow($left, $right) {
// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0)
$page_start = $this->getPage();
$y_start = $this->GetY();
// write the left cell
$this->MultiCell(150, 0, $left, 0, 'R', 0, 2, '', '', true,true,true, 0);
$page_end_1 = $this->getPage();
$y_end_1 = $this->GetY();
$this->setPage($page_start);
// write the right cell
$this->MultiCell(0, 0, $right, 0, 'R', 0, 1, $this->GetX() ,$y_start, true,true,true, 0);
$page_end_2 = $this->getPage();
$y_end_2 = $this->GetY();
// set the new row position by case
if (max($page_end_1,$page_end_2) == $page_start) {
$ynew = max($y_end_1, $y_end_2);
} elseif ($page_end_1 == $page_end_2) {
$ynew = max($y_end_1, $y_end_2);
} elseif ($page_end_1 > $page_end_2) {
$ynew = $y_end_1;
} else {
$ynew = $y_end_2;
}
$this->setPage(max($page_end_1,$page_end_2));
$this->SetXY($this->GetX(),$ynew);
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor(NOM_SOCIETE);
$pdf->SetTitle('Facture '.$id_facture);
//$pdf->SetSubject('TCPDF Tutorial');
//$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData('logo.jpg', 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('arial');
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 35);
// 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);
}
// ---------------------------------------------------------------------------------------------------------------------------
//require_once('../../../gestion_user_fns.php');
$no_client = no_client($id_facture);
$nom_client = nom_client($no_client);
$no_tel_client = no_tel_client($no_client);
$email_client = email_client($no_client);
$date_facture = inverse_date(date_facture($id_facture));
$entreprise_client = entreprise_client($no_client);
$date = date('d.m.Y');
$adresse_client = adresse_client($no_client);
$npa_client = npa_client($no_client);
$total_inter_ht = total_inter($id_facture);
$total_inter_TVA = total_inter_TVA($id_facture);
$total_mat_HT = total_mat($id_facture);
$total_mat_TVA = total_mat_TVA($id_facture);
$rabais = rabais($id_facture);
$nombre = GET_liste_mat_fact($id_facture);
$nombre = mysqli_fetch_array($nombre);
$total_HT = arrondi(total($id_facture));
$total_TVA = arrondi(total_TVA($id_facture));
if(mode_paiement($id_facture) != ""){
$mode_paiement = mode_paiement($id_facture);
}else{
$mode_paiement = "30 jours";
}
$total_TTC = arrondi(total($id_facture)+total_TVA($id_facture) - $rabais);
if ($entreprise_client != '-') {$info_client[0] = $entreprise_client.'<br>';}
if ($nom_client != ' ') {$info_client[1] = $nom_client."<br>";}
$info_client[2] = $adresse_client.'<br>';
$info_client[3] = $npa_client.'<br>';
$list_acompte = GET_acompte_PAR_id_facture($id_facture);
//echo $id_facture;
if($list_acompte){
$montant_acompte = 0;
$taxe_acompte = 0;
while($acom = mysqli_fetch_array($list_acompte)){
$montant_acompte += $acom['montant'];
$taxe_acompte += $acom['taxe'];
}
$totalAcompte = arrondi($montant_acompte + $taxe_acompte);
$total_HT = arrondi(total($id_facture) + $montant_acompte);
$total_TVA = arrondi(total_TVA($id_facture) + $taxe_acompte);
$total_TTC = arrondi(total($id_facture)+total_TVA($id_facture) + $montant_acompte + $taxe_acompte - $rabais);
$totalPayer = arrondi($total_TTC - $totalAcompte);
}
//----------------------------------------------------------------------------------------------------------------------------
// set font
$pdf->SetFont('helvetica', '', 9);
// add a page
$pdf->AddPage();
ob_start();
// set some text to print
if(FAX_SOCIETE != ''){ $fax_societe = 'Téléfax '.FAX_SOCIETE.'<br>';}
if(NUMERO_TVA_SOCIETE != ''){ $numero_tva_societe = 'N° de TVA : '.NUMERO_TVA_SOCIETE.'<br>';}
// create some HTML content
$html = '<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td> </td>
<td> </td>
<td rowspan="2">'.$info_client[0].$info_client[1].$info_client[2].($info_client[3]).'</td>
</tr>
<tr>
<td><div style="">'.NOM_SOCIETE.'<br>
'.ADRESSE_SOCIETE.' '.NUMERO_SOCIETE.'<br>
'.PAYS_SOCIETE.'-'.CODE_POSTAL_SOCIETE.' '.VILLE_SOCIETE.'
<br>Téléphone '.TELEPHONE_1_SOCIETE.'<br>
'.$fax_societe.EMAIL_SOCIETE.'<br>
'.LIEN_SOCIETE.'<br>'.$numero_tva_societe.'</div></td>
<td> </td>
</tr>
<tr>
<td>
<b>Date : '.$date_facture.'</b><br>
<b>Facture N° : '.$id_facture.'</b><br>
Paiement : '.strip_tags($mode_paiement).'
</td>
<td> </td>
<td><span style="font-size:20px;"><b>FACTURE</b></span></td>
</tr>
</table>';
// output the HTML content
$pdf->Ln(1);
$html = ($html);
$pdf->writeHTML($html, true, false, true, false, '');
$borderDashedBottom = array('T' => array('width' => 0.1, 'cap' => 'square', 'join' => 'round', 'dash' => 2, 'phase' => 0, 'color' => array(0, 0, 0)));
$borderSolidBottom = array('B' => array('width' => 0.4, 'cap' => 'butt', 'join' => 'round', 'dash' => 0, 'phase' => 1, 'color' => array(0, 0, 0)));
$pdf->SetFont('helvetica', '', 8);
//=========================================================================================================
//---------------------------------------------------------- INTERVENTIONS
//=========================================================================================================
$list_intervention_facture = GET_liste_inter_fact($id_facture);
if ($intervention = mysqli_num_rows($list_intervention_facture) != 0){
if(tva_societe($no_client) || tva_facture($id_facture)) $txt_prix = 'Prix HT';else $txt_prix = 'Prix TTC';
$pdf->Multicell(0, 5, 'Intervention(s)', $borderSolidBottom, 'L', 0, 1, '', '', true);
$pdf->Ln(1);
$pdf->MultiRowIntervention('Date', 'Description', 'Durée', $txt_prix);
$pdf->Ln(-3);
$pdf->writeHTMLCell(0, 1, 15, $y_start, '', $borderSolidBottom, 0, 0, true, 'J', true);
$pdf->Ln(5);
while ($inter = mysqli_fetch_array($list_intervention_facture))
{
$description = $inter[1];
if ($inter[2] == 0)
$temps = '-';
elseif ($inter[2] >= 60)
{
$heure = $inter[2] / 60;
$minute = $inter[2] % 60;
if ($minute == 0)
$temps = (int)$heure . 'h';
else
$temps = (int)$heure . 'h ' . $minute . 'm';
}
else
$temps = $inter[2].'m';
$date = inverse_date($inter[0]);
if(tva_societe($no_client) || tva_facture($id_facture))
$prix = arrondi($inter[3]);
else
$prix = arrondi($inter[3]+$inter[5]);
$pdf->MultiRowIntervention($date, ($description)."\n", $temps, $prix);
$pdf->Ln(0.5);
// write the line bottom
$pdf->writeHTMLCell(0, 1, 15, $y_start, '', $borderDashedBottom, 0, 0, true, 'J', true);
$pdf->Ln(0.5);
$pdf->checkPageBreak(1, '', true);
}
$pdf->Ln(10);
}
//=========================================================================================================
//---------------------------------------------------------- MATERIELS
//=========================================================================================================
if($intervention){$nL = $nL + 10;}
$list_materiel_facture = GET_liste_mat_fact($id_facture);
if ($materiel = mysqli_num_rows($list_materiel_facture) != 0)
{
if(tva_societe($no_client) || tva_facture($id_facture)) $txt_prix = 'Prix HT';else $txt_prix = 'Prix TTC';
$pdf->Multicell(0, 5, 'Materiel(s)', $borderSolidBottom, 'L', 0, 1, '', '', true);
$pdf->Ln(1);
$pdf->MultiRowMateriel('Date', 'Description', 'Nombre', 'Unitaire', $txt_prix);
$pdf->Ln(-3);
$pdf->writeHTMLCell(0, 1, 15, $y_start, '', $borderSolidBottom, 0, 0, true, 'J', true);
$pdf->Ln(5);
while ($mat = mysqli_fetch_array($list_materiel_facture))
{
$date = inverse_date($mat[0]);
$desc = strip_tags($mat[3]." - ".$mat[4]);
if(tva_societe($no_client) || tva_facture($id_facture)){
$prix_total = $mat[1] * $mat[5];
$prix = $mat[1];
}else{
$prix_total = ($mat[1] + $mat[2]) * $mat[5];
$prix = $mat[1] + $mat[2];
}
$pdf->MultiRowMateriel($date, ($desc), $mat[5], arrondi($prix), arrondi($prix_total));
$pdf->Ln(0.5);
// write the line bottom
$pdf->writeHTMLCell(0, 1, 15, $y_start, '', $borderDashedBottom, 0, 0, true, 'J', true);
$pdf->Ln(0.5);
}
}
//------------------------------------------------ LES TOTAUX
$pdf->checkPageBreak(20, '', true);
$pdf->writeHTMLCell(0, 1, 15, $y_start, '', $borderSolidBottom, 0, 0, true, 'J', true);
if(tva_societe($no_client)) {
$pdf->Ln(5);
$pdf->MultiRow('Total HT CHF', $total_HT);
if(tva_facture($id_facture)){
$txt_tva = 'Vente hors Taxe (TVA 0%) CHF';
}else{
$txt_tva = 'TVA (7.7%) CHF';
}
$pdf->MultiRow($txt_tva, $total_TVA);
}
if ($rabais){
$pdf->MultiRow('Rabais CHF', '- '.arrondi($rabais));
}
$pdf->MultiRow('<b>Prix Total TTC CHF</b>', '<b>'.$total_TTC.'</b>');
if($montant_acompte != 0){
$pdf->MultiRow('Acomptes CHF', '- '.$totalAcompte);
$pdf->MultiRow('<b>Total à payer</b>', '<b>'.$totalPayer.'</b>');
}
$pdf->Ln(-3);
$pdf->writeHTMLCell(0, 1, 15, $y_start, '', $borderSolidBottom, 0, 0, true, 'J', true);
//Close and output PDF document
$pdf->Output('pdf/factures_pdf/facture_'.$id_facture.'_'.$date_facture.'.pdf', 'F');
//============================================================+
// END OF FILE
//============================================================+
So, now I'm having the followins errors :
Warning: array_push() expects parameter 1 to be array, null given in
and
Warning: Invalid argument supplied for foreach() in
I read somewere that's a problem with the HTML tags and I need to clean up with a tool like HTML tidy but, the code is almost in PHP and I've look for something missing and I can't found it.
There's someone who can help me with this?
Thanks

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
}

PDF - barcode printing is always failing with TCPDF

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

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

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

Categories