소스 검색

Merge branch 'develop'

feature/symfony6.1
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…
취소
저장