<?php

namespace AppBundle;

use TCPDF;

class Pdf extends TCPDF
{
    private $webDir;
    private $assetManager;

    function __construct($rootDir, $assetManager)
    {
        parent::__construct('P', 'mm', 'A4', true, 'UTF-8', false, false);//($orientation, $unit, $format, $unicode, $encoding, $diskcache, $pdfa);//('P', 'mm', 'A4', true, 'UTF-8', false, false);
        $this->webDir = realpath($rootDir . '/../web');
        $this->assetManager = $assetManager;
    }

    private function getFileName($file)
    {
        $assetPath = $this->assetManager->get($file)->getTargetPath();
        $fileNameParts = explode('/', $assetPath);
        $lastPartIndex = count($fileNameParts) - 1;
        $fileName = $fileNameParts[$lastPartIndex];

        return $fileName;
    }

    public function Header()
    {
        $backgroundDir = $this->webDir.'/bundles/app/images/header-bg.png';
        $logoDir = $this->webDir.'/assetic/'.$this->getFileName('headerLogo');

        $this->Image($backgroundDir, 0, 0, 210, 0, '', '', '', false, 300, 'C');
        $this->Image($logoDir, 0, 15, 90, 0, '', '', '', false, 300, 'C');
    }

    public function Footer()
    {

        $footerDir = $this->webDir.'/assetic/'.$this->getFileName('footerText');

        $this->ImageSVG($footerDir, 0, 228, 210, '');

        $this->SetY(-58);
        $this->SetX(-30);
        $this->SetFont('helvetica', '', 10);
        $this->Cell(0, 14, 'Seite '.$this->getAliasNumPage().' von '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
    }
}

/* End of file Pdf.php */
/* Location: ./application/libraries/Pdf.php */