wp-duckbehaviorjournal/PaperPDF.php
Kumi 77949dd0c1
feat: customize PDF download header/footer
Introduced a new PaperPDF class extending TCPDF to add custom headers and footers, including the site's logo and name in the header and page numbers in the footer. Updated the PDF creation process in functions.php to utilize this new class, enhancing the branding of downloaded PDFs.
2024-08-02 22:05:49 +02:00

24 lines
No EOL
831 B
PHP

<?php
require_once get_template_directory() . '/vendor/autoload.php';
class PaperPDF extends TCPDF {
// Page header
public function Header() {
$logo_url = wp_get_attachment_image_url(get_theme_mod('custom_logo'), 'full');
if ($logo_url) {
$this->Image($logo_url, 10, 10, 50, '', '', '', 'T', false, 300, '', false, false, 0, false, false, false);
}
$this->SetFont('helvetica', 'B', 20);
$this->Cell(0, 15, get_bloginfo('name'), 0, false, 'C', 0, '', 0, false, 'T', 'M');
$this->Ln(20);
}
// Page footer
public function Footer() {
$this->SetY(-15);
$this->SetFont('helvetica', 'I', 8);
$this->Cell(0, 10, 'Page ' . $this->getAliasNumPage() . '/' . $this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}