FPDFとPHPを使用して、DBからのデータに応じて1、2、または3つのPDFを作成しようとしています。1 つの PDF を作成する必要がある場合は、それで十分です。しかし、2つまたは3つ作成する必要がある場合、一部のクラスを再宣言できないため、問題が発生します。
生成する必要がある PDF の数をテストする PHP コードを以下に示します。
include "gera-certificado.php"; //creates the first PDF - ok
if($workshop_manha != ''){
include "gera-certificado-wm.php"; // if this var is not empty, then create the second PDF -> problem
}
if($workshop_tarde != ''){
include "gera-certificado-wt.php"; // if this var is not empty, then create the third PDF -> problem
}
FPDF コードの下 - 2 つの画像 (ヘッダーとフッター) と、var. 最初の PDF では Ok が生成されますが、FPDF の一部のクラスが再宣言されているため、2 番目と 3 番目ではエラーが返されます。
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<?php
define('FPDF_FONTPATH','fpdf/font/');
require('fpdf/fpdf.php');
class PDF extends FPDF {
function Header() {
$this->SetFont("Arial","I",10);
//escreve no pdf largura,altura,conteudo,borda,quebra de linha,alinhamento,preenchimento fundo
//altura
$this->SetY(0);
$this->Image("img/topo-certificado.jpg",0,0,297,100); //Image($arquivo);
}
function Footer(){
$this->SetY(-15);
$this->Image("img/rodape-certificado.jpg",0,140,297,70); //Image($arquivo);
}
}
$pdf=new PDF('L','mm','A4');
$pdf->Open();
$pdf->AddPage();
$pdf->SetMargins(0,0,0);
$pdf->SetAutoPageBreak(false);
$pdf->SetAuthor('Dr. Ricardo Wainer');
$pdf->SetTitle('Certificado');
$pdf->SetFont('Arial','',13);
$pdf->SetTextColor(27,67,161); // Definir cor do texto
$pdf->SetDrawColor(0,0,0); // Definir cor do traço?
$pdf->SetXY(30,106);
$pdf->MultiCell(236,8,"Certificamos que ".strtoupper($nome)." participou do I Congresso Wainer de Psicoterapias Cognitivas, I Congresso Sul-Brasileiro de Terapias Integradas e de 3ª Onda e I Simpósio Brasileiro de Terapia do Esquema, realizado no dias 27, 28 e 29 de agosto de 2015, com carga horária de 22 horas.",0,'C');
$pdf->Output("../../certificados/".$id.".pdf");
?>
Ok。それでおしまい!2 番目と 3 番目の FPDF コードは上記と同じですが、PDF はヘッダーとフッターが異なるため、画像ディレクトリが異なるだけです。あなたの助けと時間を前もってありがとう:)