All checks were successful
Deploy bericht / deploy (push) Successful in 1s
TCPDF::addTTFfont produziert bei allen 4 Hack-TTFs den gleichen Key 'hack' (PostScript-Family-Kollision) und erzeugt eine hack.php die sich selbst überschreibt. Der HTML-Parser löst bei <b>/<i>-Tags dann SetFont-Calls aus, die auf nicht-existente Style-Varianten fallen zurück und mit 'Could not include font definition file: hack' abbrechen — keine Menge an SetFont-Overrides fängt das zuverlässig ab. Lösung: hack_font_key = helvetica. PDF-Generation funktioniert garantiert. Hack wird später mit vorab-offline-konvertierten .php-Definitionen neu eingebunden.
81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* BerichtPdf — TCPDF/FPDI-Subclass mit Header, Footer und Hack-Font-Setup
|
|
* für das Bericht-Modul.
|
|
*
|
|
* Header: links Bericht-Titel + Firmenname, rechts Firmen-Logo, Trennlinie.
|
|
* Footer: zentriert "Seite X / Y".
|
|
* Font: Hack-TTFs werden in ein beschreibbares DOL_DATA_ROOT/bericht/tcpdf_fonts/
|
|
* kompiliert und per AddFont an die PDF-Instance gebunden.
|
|
*/
|
|
|
|
trait BerichtPdfTrait
|
|
{
|
|
public $hack_font_key = 'helvetica';
|
|
public $hack_font_styles = array(); // style => font-family-key
|
|
public $bericht_title = '';
|
|
public $bericht_company = '';
|
|
public $bericht_logo = '';
|
|
|
|
/**
|
|
* Muss direkt nach der Konstruktion aufgerufen werden.
|
|
*/
|
|
public function berichtInit($title, $company, $logo_path)
|
|
{
|
|
$this->bericht_title = (string) $title;
|
|
$this->bericht_company = (string) $company;
|
|
$this->bericht_logo = (string) $logo_path;
|
|
|
|
// TODO: Hack-Font später mit vorab-konvertierten TCPDF-Definitionen
|
|
// einbinden. TCPDF::addTTFfont zur Laufzeit funktioniert für Hack
|
|
// nicht (PostScript-Family-Kollision "hack" zwischen Regular/Bold/
|
|
// Italic → hack.php überschreibt sich selbst, SetFont-Fallbacks
|
|
// brechen HTML-Rendering ab). Bis dahin: Standard-Helvetica.
|
|
$this->hack_font_key = 'helvetica';
|
|
}
|
|
|
|
public function Header()
|
|
{
|
|
$pageW = $this->getPageWidth();
|
|
$logo_w = 0;
|
|
if ($this->bericht_logo && file_exists($this->bericht_logo)) {
|
|
$info = @getimagesize($this->bericht_logo);
|
|
if ($info && $info[0] && $info[1]) {
|
|
$maxW = 40; $maxH = 18;
|
|
$ratio = min($maxW / $info[0], $maxH / $info[1]);
|
|
$w = $info[0] * $ratio;
|
|
$h = $info[1] * $ratio;
|
|
$this->Image($this->bericht_logo, $pageW - 10 - $w, 6, $w, $h);
|
|
$logo_w = $w;
|
|
}
|
|
}
|
|
$this->SetTextColor(40, 40, 40);
|
|
$this->SetFont($this->hack_font_key, 'B', 13);
|
|
$this->SetXY(10, 8);
|
|
$textW = $pageW - 20 - $logo_w - 4;
|
|
$this->Cell($textW, 6, $this->bericht_title, 0, 2, 'L');
|
|
if ($this->bericht_company) {
|
|
$this->SetFont($this->hack_font_key, '', 9);
|
|
$this->SetX(10);
|
|
$this->Cell($textW, 5, $this->bericht_company, 0, 2, 'L');
|
|
}
|
|
$this->SetDrawColor(180, 180, 180);
|
|
$this->SetLineWidth(0.2);
|
|
$this->Line(10, 27, $pageW - 10, 27);
|
|
}
|
|
|
|
public function Footer()
|
|
{
|
|
$this->SetY(-12);
|
|
$this->SetFont($this->hack_font_key, '', 9);
|
|
$this->SetTextColor(100, 100, 100);
|
|
$txt = 'Seite '.$this->getAliasNumPage().' / '.$this->getAliasNbPages();
|
|
$this->Cell(0, 8, $txt, 0, 0, 'C');
|
|
}
|
|
}
|
|
|
|
class BerichtPdf extends TCPDF { use BerichtPdfTrait; }
|
|
|
|
if (class_exists('\\setasign\\Fpdi\\Tcpdf\\Fpdi')) {
|
|
class BerichtPdfFpdi extends \setasign\Fpdi\Tcpdf\Fpdi { use BerichtPdfTrait; }
|
|
}
|