TCPDF 中未显示的标头

问题描述

我想用 TCPDF 在 PDF 页面上设置页眉和页脚。

在@Simone Rossaini 的评论帮助下,我尝试这样做:

    <?PHP
require_once('C:\Users\Administrateur\Desktop\testjelix\vendor\tecnickcom\tcpdf\examples\tcpdf_include.PHP');

// create new PDF document
$pdf = new TCPDF;
class fdr extends TCPDF {

    //Page header
    public function Header() {        
        // Set font
        $this->SetFont('helvetica','B',35);
        // Title
        //Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='',$stretch=0,$ignore_min_height=false,$calign='T',$valign='M')
        $this->Cell(0,'Feuille de route',false,'C','','M','M');
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica','I',8);
        // Page number
        $this->Cell(0,10,'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(),'T','M');
        //date time
        $tDate = date("F j,Y,g:i a");
        $this->Cell(0,'Document généré par Wee.org le '.$tDate,'R','M');      
    }
}

// create new PDF document
$pdf = new fdr(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false);

// set document information
$pdf->SetCreator(PDFCREATOR);
$pdf->SetAuthor('Wee');
$pdf->SetTitle('Feuille de route');
$pdf->SetSubject('GBiuac');
$pdf->SetKeywords('TCPDF,PDF,example,test,guide');

// set font
$pdf->SetFont('helvetica',11);

// add a page
$pdf->AddPage('L','A4');

//Image($file,$x='',$y='',$w=0,$type='',$resize=false,$dpi=300,$palign='',$ismask=false,$imgmask=false,$fitBox=false,$hidden=false,$fitonpage=false)
$pdf->Image('C:\Users\Administrateur\Desktop\testjelix\gp-logo.jpg',"",35,300,'L',1,false); 
$pdf->Ln(40);
//Cell($w,$valign='M')
$pdf->Cell(0,'COVID 19',1);
//MultiCell(w,h,txt,border = 0,align = 'J',fill = 0,ln = 1,x = '',y = '',reseth = true,stretch = 0,ishtml = false,autopadding = true,maxh = 0) ⇒ Object
$pdf->MultiCell(0,2,'En raison des mesures Covid,nous prenons toutes les mesures nécessaires pour la sécurité et la sérénité de nos invités et du public.Le port du masque est obligatoire pour tous vos rendez-vous - Les règles sanitaires à respecter seront indiquées à l\'entrée de chaque lieu du Festival. Un masque spécial vous sera donné à votre arrivée.',true);
$pdf->Cell(0,'SOIREE',3);
$pdf->MultiCell(0,'Chaque soir,après votre séance,nous vous donnons RDV au Garage / Librairie des Bauges à partir de 22:00,22:30 pour partager un moment autour d\'un verre (ou non). En toute sécurité et quiétude.','VOUS ET VOTRE CHARGE D\'ACCUEIL',3);

   $tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
    <tr>
        <td align="center" style="background-color:#FFFF00">Prénom</td>
        <td align="center" style="background-color:#FFFF00">Nom</td>        
        <td align="center" style="background-color:#FFFF00">Téléphone</td>
        <td align="center" >Chargé d'accueil</td>
        <td align="center" style="background-color:#D9E7FD">JS</td>
        <td align="center" style="background-color:#D9E7FD">ESNLT</td>
        <td align="center" style="background-color:#D9E7FD">06 70 80</td>
    </tr>
    <tr>
        <td align="center" colspan="4"></td>
        <td align="center" style="background-color:#D9E7FD">Max</td>
        <td align="center" style="background-color:#D9E7FD">JAZZAVILLE</td>
        <td align="center" style="background-color:#D9E7FD">59 78</td>
    </tr>
</table>
EOD;

$pdf->writeHTML($tbl,'');

$pdf->Cell(0,'TRANSPORTS',3);
 $tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
    <tr>
        <td align="center" colspan="6">Transport SNCF</td>
        <td align="center" colspan="2">Véhicule Personnel</td>
    </tr>
    <tr>
        <th align="center" rowspan="1">Lieu d'arrivée</th>
        <th align="center" style="background-color:#FFFF00">Chambéry</th>
        <th align="center">Date et horaire d'arrivée Train</th>
        <th align="center" style="background-color:#FFFF00">13:18</th>
        <th align="center">Horaire de RDV pour transfert</th>
        <th align="center" style="background-color:#FFFF00">13:20</th>
        <th align="center" rowspan="2">Lieu de RDV</th>
        <th align="center" rowspan="2">Salle de la Municipalité - Hôtel de Ville</th>
    </tr>
     <tr>
        <th align="center" rowspan="1">Lieu de départ</th>
        <th align="center" style="background-color:#FFFF00">Chambéry</th>
        <th align="center">Date et horaire départ Train</th>
        <th align="center" style="background-color:#FFFF00">10:22</th>
        <th align="center">Horaire de RDV pour transfert</th>
        <th align="center" style="background-color:#FFFF00">9:00</th>
    </tr>
    <tr>
        <th align="center" rowspan="2" colspan="2" >Contact Bureau Transport</th>
        <th align="center" colspan="2">M. Denis BOHAN</th>
        <th align="center" colspan="2">06 08 86  26 22</th>
        <th align="center" colspan="4"rowspan="2">Parking : Parking du Palais de Justice - 12 cours de l'Hôtel de Ville</th>
    </tr>
     <tr>
        <th align="center" colspan="2">M. François GIORS</th>
        <th align="center" colspan="2">06 27 15 18 31</th>
    </tr>
</table>
EOD;

$pdf->writeHTML($tbl,'HEBERGEMENT',3);
   $tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
     <tr>
        <th align="center" colspan="2">Lieu</th>
        <th align="center" colspan="6">Résidence 3*** Citadelle de Conflans - Place de Conflans 73200 ALBERTVILLE</th>
    </tr>
    <tr>
        <th align="center" colspan="2">Code porte</th>
        <th align="center" colspan="6">07200 - En cas de problèmes d'ouverture : 04 79 37 84 60</th>
    </tr>
     <tr>
        <th align="center" colspan="2" rowspan="2">Nuitée</th>
        <th align="center" colspan="1">jeudi 15 octobre</th>
        <th align="center" colspan="1">vendredi 16 octobre</th>
        <th align="center" colspan="1">samedi 17 octobre</th>
        <th align="center" colspan="1">dimanche 18 octobre</th>
        <th align="center" rowspan="3">CHAMBRE</th>
    </tr>
    <tr>
        <th align="center" style="background-color:#FFFF00"></th>
        <th align="center" style="background-color:#FFFF00"></th>
        <th align="center" style="background-color:#FFFF00"></th>
        <th align="center" style="background-color:#FFFF00">7</th>        
    </tr>
</table>
EOD;

$pdf->writeHTML($tbl,'');

// add a page
$pdf->AddPage('L','A4');
$pdf->Cell(0,'RESTAURATION CATERING',3);
 $tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
     <tr>
        <th align="center" colspan="2">Lieu</th>
        <th align="center" colspan="6">Salle René Cassin</th>
    </tr>
    <tr>
        <th align="center" colspan="2">Repas Menu</th>
        <th align="center" colspan="6">Cantine bio - Repas bio à dominante végétarienne</th>
    </tr>
     <tr>
        <th align="center">Horaires de service</th>
        <th align="center" colspan="2">Midi de 11:30 à 14:00</th>
        <th align="center" colspan="2">Soir de 18:30 à 21:30</th>
        <th align="center">Signaler un retard ou une demande</th>
        <th align="center">Mme Bernadette </th>
        <th align="center">06 61 20 10</th>
    </tr>
    <tr>
        <th align="center" colspan= "3">Régime alimentaire signalé par l'invité</th>
        <th align="center" colspan= "5"></th>
    </tr>
    <tr>
        <th align="center" rowspan = "2">Repas prévus</th>
        <th align="center">jeudi 15 soir</th>
        <th align="center">vendredi 16 midi</th>
        <th align="center">vendredi 16 soir</th>
        <th align="center">samedi 17 midi</th>
        <th align="center">samedi 17 soir</th>
        <th align="center">dimanche 18 midi</th>
        <th align="center">dimanche 18 soir</th>
    </tr>
    <tr>
        <th align="center" style="background-color:#FFFF00">0</th>
        <th align="center" style="background-color:#FFFF00">0</th>
        <th align="center" style="background-color:#FFFF00">0</th>
        <th align="center" style="background-color:#FFFF00">0</th>
        <th align="center" style="background-color:#FFFF00">0</th>
        <th align="center" style="background-color:#FFFF00">7</th>
        <th align="center"style="background-color:#FFFF00">GaraGE 7 + MAX</th>
    </tr>
    <tr align="center" colspan="8">Vous avez été informé par la présente feuille de route de la commande de vos repas. Nous vous remercions de la respecter afin d'éviter tout gaspillage,qui serait incohérent avec les valeurs que nous défendons. Si vous souhaitez ne pas bénéficier des repas et les prendre en dehors de l'organisation à votre charge,nous vous remercions d'informer M. Jean Sébastien ESNAULT 06 03 70 80
    </tr>
</table>
<br/>
<br/>
<br/>
<br/>
EOD;

$pdf->writeHTML($tbl,'VOTRE PLANNING',3);

$tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
     <tr>
        <th align="center" colspan="2">Date et heure</th>
        <th align="center" colspan="2">Vos rendez vous</th>
        <th align="center" colspan="1">Lieu</th>
        <th align="center" colspan="1">Heure RDV</th>
        <th align="center" colspan="1">Contact Animateur</th>
        <th align="center" colspan="1">Infos complémentaires</th>
    </tr>
    <tr>
        <th align="center" colspan="2">14:00</th>
        <th align="center" colspan="2">Catering + Raccord</th>
        <th align="center" colspan="1">René CASSIN</th>
        <th align="center" colspan="1">14:00</th>
        <th align="center" colspan="1">JS ESNAULT 06 70 80 </th>
        <th align="center" colspan="1"></th>
    </tr>
     <tr>
        <th align="center" colspan="2">15:00</th>
        <th align="center" colspan="2">Dépose Bagages Citadelle + Prise de clés</th>
        <th align="center" colspan="1">Citadelle</th>
        <th align="center" colspan="1">15:00</th>
        <th align="center" colspan="1">JS ESNAULT 06 03 00 70 80 </th>
        <th align="center" colspan="1"></th>
    </tr>
    <tr>
        <th align="center" colspan="2">15:30 > 17:15</th>
        <th align="center" colspan="2">Arrivée Dôme : montage,patch,balances</th>
        <th align="center" colspan="1">Dôme Théâtre</th>
        <th align="center" colspan="1">15:30</th>
        <th align="center" colspan="1">JS ESNAULT 06 03 70 80</th>
        <th align="center" colspan="1"></th>
    </tr>
    <tr>
        <th align="center" colspan="2">17:45 (+ ou - 10 minutes)</th>
        <th align="center" colspan="2">Concert / Fin 19:00 à 19:20</th>
        <th align="center" colspan="1">Dôme Théâtre</th>
        <th align="center" colspan="1"></th>
        <th align="center" colspan="1">JS ESNAULT 06 70 80</th>
        <th align="center" colspan="1"></th>
    </tr>
     <tr align="center">BILLETS EXONERES >Assister à des séances en dehors de vos interventions</tr>
     <br/>
     <tr align="center">Veuillez prendre contact avec votre chargé d'accueil à l'arrivée pour voir quelles séances peuvent être disponbiles et combinables avec votre planning et votre présence.</tr>
</table>
EOD;

$pdf->writeHTML($tbl,'');

$pdf->AddPage('L','A4');

$pdf->Cell(0,'VOS CONTACTS UTILES',3);
 $tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
     <tr>
        <th align="center">Votre chargé d'accueil</th>
        <th align="center">Chantal</th>
        <th align="center">BOA</th>
        <th align="center">06 37 87 1</th>
    </tr>
    <tr>
        <th align="center">Chargé d'accueil (au cas où le vôtre n'est pas disponible)</th>
        <th align="center">Jannick</th>
        <th align="center">LADY</th>
        <th align="center">06 11 57 39 90</th>
    </tr>
    <tr>
        <th align="center">Délégué Général  du Festival</th>
        <th align="center">Jean Sébastien</th>
        <th align="center">ESNT</th>
        <th align="center">06 03 80</th>
    </tr>
    <tr>
        <th align="center">Transports et navettes</th>
        <th align="center">Denis</th>
        <th align="center">Bon</th>
        <th align="center">06 26 22</th>
    </tr>
    <tr>
        <th align="center">Hébergement - Citadelle de Conflans</th>
        <th align="center"></th>
        <th align="center"></th>
        <th align="center">04 84 60</th>
    </tr>
    <tr>
        <th align="center">Restauration Catering</th>
        <th align="center">Bernadette</th>
        <th align="center">PAVILLIERS</th>
        <th align="center">06 61 10</th>
    </tr>
</table>
EOD;

$pdf->writeHTML($tbl,'');

$pdf->Ln(6);


// example using general stretching and spacing


// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('fdr.pdf','I');

//============================================================+
// END OF FILE
//============================================================

但是,没有显示任何内容......我的页眉顶部有一个带有黑线的空白区域......下面是我其余代码的行和底部,页脚没有任何内容

如何应用这些功能?我们应该在下面给他们回电吗?

感谢您的帮助或解释。

screencap

解决方法

你扩展了类,但你不使用它。

您需要扩展它,然后使用您选择的名称来使用 new:

require_once('C:\Users\Administrateur\testjelix\vendor\tecnickcom\tcpdf\examples\tcpdf_include.php');
class FdrPdf extends TCPDF {

    private $invoice_footer;

    //Page header
    public function Header() {
        // Logo
        $image_file = K_PATH_IMAGES . 'C:\Users\Administrateur\testjelix\gp-logo.jpg';
        $this->Image($image_file,10,15,'','JPG','T',false,300,false);
        // Set font
        $this->SetFont('helvetica','B',35);
        // Title
        $this->Cell(0,'Feuille de route','C','M','M');
    }

    // Page footer
    public function Footer() {
        // Position at 15 mm from bottom
        $this->SetY(-15);
        // Set font
        $this->SetFont('helvetica','I',8);
        // Page number
        $this->Cell(0,'Page ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(),'M');
        $this->invoice_footer = 'Document généré le ' . $dtnow->toString(jDateTime::LANG_DFORMAT) . ' à ' . substr($dtnow->toString(jDateTime::LANG_TFORMAT),-3) . ' via me.org - www.me.org';
    }

}

// create new PDF document
$pdf = new FdrPdf;
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Me');
$pdf->SetTitle('Feuille de route');
$pdf->SetSubject('GB');
$pdf->SetKeywords('TCPDF,PDF,example,test,guide');
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE,PDF_MARGIN_BOTTOM);
// ---------------------------------------------------------
// set font
$pdf->SetFont('helvetica',35);
// add a page
$pdf->AddPage('L','A4');
$pdf->setPrintHeader(true);
$pdf->setPrintFooter(true);
$pdf->Ln(40);
$pdf->SetFont('helvetica',11);
//Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='',$stretch=0,$ignore_min_height=false,$calign='T',$valign='M')
$pdf->Cell(0,'COVID 19',1,1);
$pdf->MultiCell(0,2,'En raison des mesures Covid,nous prenons toutes les mesures nécessaires pour la sécurité et la sérénité de nos invités et du public.Le port du masque est obligatoire pour tous vos rendez-vous - Les règles sanitaires à respecter seront indiquées à l\'entrée de chaque lieu du Festival. Un masque spécial vous sera donné à votre arrivée.',true);
$pdf->Cell(0,'SOIREE',3);
$pdf->MultiCell(0,'Chaque soir,après votre séance,nous vous donnons RDV au Garage / Librairie des Bauges à partir de 22:00,22:30 pour partager un moment autour d\'un verre (ou non). En toute sécurité et quiétude.',true);

$pdf->Cell(0,'VOUS ET VOTRE CHARGE D\'ACCUEIL',3);

$tbl = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
    <tr>
        <td align="center" style="background-color:#FFFF00">Prénom</td>
        <td align="center" style="background-color:#FFFF00">Nom</td>        
        <td align="center" style="background-color:#FFFF00">Téléphone</td>
        <td align="center" >Chargé d'accueil</td>
        <td align="center" style="background-color:#D9E7FD">JS</td>
        <td align="center" style="background-color:#D9E7FD">ESNAULT</td>
        <td align="center" style="background-color:#D9E7FD">06 03 00 70 80</td>
    </tr>
    <tr>
        <td align="center" colspan="4"></td>
        <td align="center" style="background-color:#D9E7FD">Max</td>
        <td align="center" style="background-color:#D9E7FD">JAZZALBERTVILLE</td>
        <td align="center" style="background-color:#D9E7FD">06 98 54 59 78</td>
    </tr>
</table>
EOD;

$pdf->writeHTML($tbl,true,'');
$pdf->Output('test.pdf','I');
exit;

另一个问题是 $dtnow 不存在于函数中,如果您在外部使用 global $dtnow 并且一切正常。