#php #header #tcpdf
Вопрос:
Я хочу настроить верхний и нижний колонтитулы на странице PDF с помощью TCPDF.
Я стараюсь сделать это с помощью @ Simone Rossaini в комментариях :
<?php
require_once('C:UsersAdministrateurDesktoptestjelixvendortecnickcomtcpdfexamplestcpdf_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, 0, 'Feuille de route', 0, false, 'C', 0, '', 0, false, '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(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
//date time
$tDate = date("F j, Y, g:i a");
$this->Cell(0, 10, 'Document généré par Wee.org le '.$tDate, 0, false, 'R', 0, '', 0, false, 'T', '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, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false)
$pdf->Image('C:UsersAdministrateurDesktoptestjelixgp-logo.jpg', '', '', "", 35, '', '', 'T', false, 300, 'L', false, false, 1, false, false, false);
$pdf->Ln(40);
//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, 0, 'COVID 19', 1, 1, 'C', 0, '', 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.', 0, '', 0, 1, '', '', true);
$pdf->Cell(0, 0, 'SOIREE', 1, 2, 'C', 0, '', 3);
$pdf->MultiCell(0, 2, '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.', 0, '', 0, 1, '', '', true);
$pdf->Cell(0, 0, 'VOUS ET VOTRE CHARGE D'ACCUEIL', 1, 1, 'C', 0, '', 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, true, false, false, false, '');
$pdf->Cell(0, 0, 'TRANSPORTS', 1, 1, 'C', 0, '', 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, true, false, false, false, '');
$pdf->Cell(0, 0, 'HEBERGEMENT', 1, 1, 'C', 0, '', 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, true, false, false, false, '');
// add a page
$pdf->AddPage('L', 'A4');
$pdf->Cell(0, 0, 'RESTAURATION CATERING', 1, 1, 'C', 0, '', 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, true, false, false, false, '');
$pdf->Cell(0, 0, 'VOTRE PLANNING', 1, 1, 'C', 0, '', 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, true, false, false, false, '');
$pdf->AddPage('L', 'A4');
$pdf->Cell(0, 0, 'VOS CONTACTS UTILES', 1, 1, 'C', 0, '', 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, true, false, false, false, '');
$pdf->Ln(6);
// example using general stretching and spacing
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('FDR.pdf', 'I');
//============================================================
// END OF FILE
//============================================================
Однако ничего не отображается … У меня есть белое пространство с черной линией в верхней части заголовка … ниже мои строки остальной части кода, а внизу ничего для нижнего колонтитула.
как применить эти функции? Должны ли мы перезвонить им внизу?
Спасибо за любую помощь или объяснение.
Комментарии:
1. Это все твой код?
2. Нет, у меня много подписчиков, я только что опубликовал начало.
3. Только заголовок не отображается?
4. Нет, нижний колонтитул тоже не отображается. Я совсем не разбираюсь в синтаксисе, и я взял это из примера, подобного этому : tcpdf.org/examples/example_003 . Я думал, что у меня все хорошо, и я не знаю, что застряло
5.
$pdf->setPrintHeader(true); $pdf->setPrintFooter(true);
Добавьте эту строку, если у вас ее нет.
Ответ №1:
Вы расширяете класс, но не используете его.
Вам нужно расширить его, а затем использовать новый с именем, которое вы выбираете, как:
require_once('C:UsersAdministrateurtestjelixvendortecnickcomtcpdfexamplestcpdf_include.php');
class FdrPdf extends TCPDF {
private $invoice_footer;
//Page header
public function Header() {
// Logo
$image_file = K_PATH_IMAGES . 'C:UsersAdministrateurtestjelixgp-logo.jpg';
$this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', 'B', 35);
// Title
$this->Cell(0, 15, 'Feuille de route', 0, false, 'C', 0, '', 0, false, '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(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
$this->invoice_footer = 'Document généré le ' . $dtnow->toString(jDateTime::LANG_DFORMAT) . ' à ' . substr($dtnow->toString(jDateTime::LANG_TFORMAT), 0, -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, 0, 'COVID 19', 1, 1, 'C', 0, '', 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.', 0, '', 0, 1, '', '', true);
$pdf->Cell(0, 0, 'SOIREE', 1, 2, 'C', 0, '', 3);
$pdf->MultiCell(0, 2, '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.', 0, '', 0, 1, '', '', true);
$pdf->Cell(0, 0, 'VOUS ET VOTRE CHARGE D'ACCUEIL', 1, 1, 'C', 0, '', 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, false, false, false, '');
$pdf->Output('test.pdf', 'I');
exit;
Другая проблема заключается $dtnow
в том, что функция не существует, если она используется вне global $dtnow
вас и все работает.