Wie kann ich eine Fußzeile mit tcpdf bearbeiten? Ich möchte das aktuelle Datum und die Uhrzeit in die Fußzeile einfügen. Bitte helfen Sie mir.
Antworten
Zu viele Anzeigen?Überschreiben Sie die Klasse wie folgt:
class MYPDF extends TCPDF {
public function Footer() {
$image_file = "img/bg_bottom_releve.jpg";
$this->Image($image_file, 11, 241, 189, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
$this->SetY(-15);
$this->SetFont('helvetica', 'N', 6);
$this->Cell(0, 5, date("m/d/Y H\hi:s"), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
dann statt des Aufrufs von :
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
tun:
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
Sie müssen die TCPDF-Klasse erweitern und die Footer()-Methode überschreiben, wie im Standardbeispiel n erklärt. 3. Prüfen Sie die offizielle http://www.tcpdf.org Website und Foren für weitere Informationen.
Wie kann ich bitte 2 Fußzeilen erstellen?
class MYPDF extends TCPDF {
private $customFooterText = "";
/**
* @param string $customFooterText
*/
public function setCustomFooterText($customFooterText)
{
$this->customFooterText = $customFooterText;
}
public function Footer()
{
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, $this->customFooterText, 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
Verwendung
$pdf = new MYPDF();
$pdf->setCustomFooterText('THIS IS CUSTOM FOOTER');
Wenn Sie den Fußzeilentext dynamisch ändern wollen, erweitert TCPDF wie folgt
class MYPDF extends TCPDF {
private $customFooterText = "";
/**
* @param string $customFooterText
*/
public function setCustomFooterText($customFooterText)
{
$this->customFooterText = $customFooterText;
}
public function Footer()
{
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'I', 8);
// Page number
$this->Cell(0, 10, $this->customFooterText, 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
Verwendung:
$pdf = new MYPDF();
$pdf->setCustomFooterText('THIS IS CUSTOM FOOTER');
// .... etc
Wenn Sie einen anderen Inhalt auf mehr als eine Seite stellen wollen:
define("bottom_info", "|FIRST PAGE|SECOND PAGE|THIRD PAGE|...", true);
die Informationen werden durch " | " getrennt (mit Explode-Funktion)
Klasse:
class MYPDF extends TCPDF {
public function Header() {
}
// Page footer
public function Footer() {
$this->SetY(-15);
$this->SetFont('helvetica', '', 7);
// Page number
$titulos = explode("|",bottom_info);
$this->Cell(0, 10, $titulos[$this->page].' - Pagina '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
- See previous answers
- Weitere Antworten anzeigen