Ver código fonte

Création PdfGenerator

feature/symfony6.1
Guillaume 2 anos atrás
pai
commit
f3a670ab09
2 arquivos alterados com 38 adições e 0 exclusões
  1. +7
    -0
      Controller/ControllerTrait.php
  2. +31
    -0
      Generator/PdfGenerator.php

+ 7
- 0
Controller/ControllerTrait.php Ver arquivo

@@ -19,6 +19,7 @@ use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Field\Filter\FilterManager;
use Lc\SovBundle\Generator\PdfGenerator;
use Lc\SovBundle\Repository\EntityRepository;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\FlashBagTranslator;
@@ -53,6 +54,7 @@ trait ControllerTrait
LoggerInterface::class => LoggerInterface::class,
ParameterBagInterface::class => ParameterBagInterface::class,
TranslatorInterface::class => TranslatorInterface::class,
PdfGenerator::class => PdfGenerator::class,
TranslatorAdmin::class => TranslatorAdmin::class,
FilterManager::class => FilterManager::class,
FlashBagTranslator::class => FlashBagTranslator::class,
@@ -177,6 +179,11 @@ trait ControllerTrait
return $this->get(TranslatorInterface::class);
}

public function getPdfGenerator(): PdfGenerator
{
return $this->get(PdfGenerator::class);
}

public function getTranslatorAdmin(): TranslatorAdmin
{
return $this->get(TranslatorAdmin::class);

+ 31
- 0
Generator/PdfGenerator.php Ver arquivo

@@ -0,0 +1,31 @@
<?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
]);
}
}

Carregando…
Cancelar
Salvar