core/lib/Thelia/Action/Pdf.php line 27

  1. <?php
  2. /*
  3.  * This file is part of the Thelia package.
  4.  * http://www.thelia.net
  5.  *
  6.  * (c) OpenStudio <info@thelia.net>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Thelia\Action;
  12. use Spipu\Html2Pdf\Html2Pdf;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Thelia\Core\Event\PdfEvent;
  15. use Thelia\Core\Event\TheliaEvents;
  16. /**
  17.  * Class Pdf.
  18.  *
  19.  * @author Manuel Raynaud <manu@raynaud.io>
  20.  */
  21. class Pdf extends BaseAction implements EventSubscriberInterface
  22. {
  23.     public function generatePdf(PdfEvent $event): void
  24.     {
  25.         $html2pdf = new Html2Pdf(
  26.             $event->getOrientation(),
  27.             $event->getFormat(),
  28.             $event->getLang(),
  29.             $event->getUnicode(),
  30.             $event->getEncoding(),
  31.             $event->getMarges()
  32.         );
  33.         $html2pdf->setDefaultFont($event->getFontName());
  34.         $html2pdf->pdf->SetDisplayMode('real');
  35.         $html2pdf->writeHTML($event->getContent());
  36.         $event->setPdf($html2pdf->output('output.pdf''S'));
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public static function getSubscribedEvents()
  42.     {
  43.         return [
  44.             TheliaEvents::GENERATE_PDF => ['generatePdf'128],
  45.         ];
  46.     }
  47. }