I'm having a problem with FPDF because my class extend it's not working.
I'm creating a class for my footer and then call it with:
$pdf = new PDF2();
I have the code in a external file with an include above all the code, like this:
include"fpdf.php";
class PDF2 extends TFPDF
{
// Page footer
function Footer()
{
// MB LOGO 30cm before the end of the page
$Y = $this->SetY(-65);
// Arial italic 8
$this->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$this->SetFont('DejaVu','',10);
//MB LOGO
$this->Image('img/multibanco.jpg',20,$Y,30);
}
}
//pdf begins
// Cliente info encomenda
$pdf = new tFPDF();
$pdf = new PDF();
$pdf = new PDF2();
$pdf->addPage();
// Arial bold 15
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',11);
// Title
$pdf->Cell(190,10,'Ordem Nº '.$maxi.'',0,0,'C');
// Line break
$pdf->Ln(20);
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',10);
// Cliente nome/email
$pdf->Cell(150,10,'Cliente: '.$enc['nome'].' '.$enc['apelido'].' ',0,1);
$pdf->Cell(150,10,'Email: '.$enc['email'].'',0,1);
$pdf->setFillColor(232, 232, 232);
//Messagem
$pdf->RoundedRect(10, 50, 190, 10, 3.5,TRUE);
$pdf->Cell(190,10,'Mensagem',0,1,'L'); //header
$pdf->setFillColor(255, 255, 255); // background
$pdf->MultiCell(180,5,'Text',0,'J',0); // MENSAGEM
//TABELA
$html ='';
$html='<table border="0">
<tr>
<td width="230" height="40" bgcolor="#e6e6e6">Tipo</td>
<td width="88" height="40" bgcolor="#e6e6e6">Formato</td>
<td width="88" height="40" bgcolor="#e6e6e6">Nº Interno</td>
<td width="88" height="40" bgcolor="#e6e6e6">Revelar</td>
<td width="88" height="40" bgcolor="#e6e6e6">Digitalizar</td>
<td width="88" height="40" bgcolor="#e6e6e6">Edição</td>
<td width="88" height="40" bgcolor="#e6e6e6">Impressão</td>
</tr>';
while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
$html .= '
<tr>
<td width="230" height="40" bgcolor="#f7f7f7">'.$pdf_info2['Tipo'].'</td>
<td width="88" height="40" bgcolor="#f7f7f7">'.$pdf_info2['Formato'].'</td>
<td width="88" height="40" bgcolor="#f7f7f7"> </td>
<td width="88" height="40" bgcolor="#f7f7f7">'.$pdf_info2['Revelar'].'</td>
<td width="88" height="40" bgcolor="#f7f7f7">'.$pdf_info2['Digitalizar'].'</td>
<td width="88" height="40" bgcolor="#f7f7f7">'.$pdf_info2['Edicao'].'</td>
<td width="88" height="40" bgcolor="#f7f7f7">'.$pdf_info2['Impressao'].'</td>
</tr>';
}
$pdf->WriteHTML($html);
//OUTPUT + LN
$pdf->Ln(10);
$pdf->Output();
Any errors of the class are not displayed, at least I don't see them even without the error_reporting(0) commented.
You must not declare the object $pdf
more than once, you must call the file tfpdf.php, there is built the class tFPDF()
.
Example
<?php
// Optionally define the filesystem path to your system fonts
// otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory
// define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/");
require('tfpdf.php');
$pdf = new tFPDF();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',14);
// Load a UTF-8 string from a file and print it
$txt = file_get_contents('HelloWorld.txt');
$pdf->Write(8,$txt);
// Select a standard font (uses windows-1252)
$pdf->SetFont('Arial','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 12 KB.');
$pdf->Output();
?>
Download the class tFPDF() in http://www.fpdf.org