我遇到FPDF问题,因为我的班级延长了它没有用。
我为我的页脚创建了一个类,然后用:
调用它$pdf = new PDF2();
我将代码放在外部文件中,其中包含所有代码,如下所示:
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();
不会显示班级的任何错误,至少我没有看到错误报告(0)的评论。
答案 0 :(得分:0)
你不能多次声明对象$pdf
,你必须调用文件tfpdf.php,构建了类tFPDF()
。
实施例
<?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();
?>
中下载课程tFPDF()