<?php

namespace Lc\SovBundle\Generator;

use Dompdf\Dompdf;
use Dompdf\Options;
use Twig\Environment;

class PdfGenerator
{
    protected Environment $templating;

    public function __construct(Environment $templating)
    {
        $this->templating = $templating;
    }

    public function render($filename, $view, $viewParams)
    {
        $pdfOptions = new Options();
        $pdfOptions->set('defaultFont', 'Arial');
        $dompdf = new Dompdf($pdfOptions);
        $html = $this->templating->render($view, $viewParams);
        $dompdf->loadHtml($html);
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->render();
        $dompdf->stream($filename, [
                "Attachment" => true
        ]);
        die();
    }
}