Преглед на файлове

Merge branch 'develop'

develop
Guillaume преди 3 години
родител
ревизия
74a170d008
променени са 2 файла, в които са добавени 38 реда и са изтрити 0 реда
  1. +7
    -0
      Controller/ControllerTrait.php
  2. +31
    -0
      Generator/PdfGenerator.php

+ 7
- 0
Controller/ControllerTrait.php Целия файл

@@ -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 Целия файл

@@ -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
]);
}
}

Loading…
Отказ
Запис