Exemplo n.º 1
0
 /**
  * @return array
  */
 public function exampleAction()
 {
     $pdf = new PdfTransfer();
     $content = new PdfTemplateTransfer();
     $content->setPath('@pdf/content.twig');
     $content->setType(PdfConfig::TEMPLATE_TYPE_TWIG);
     $content->setParameter(['entity' => ['items' => [['name' => 'Item 1', 'price' => 1299], ['name' => 'Item 2', 'price' => 1599]], 'total' => 2898]]);
     $header = new PdfTemplateTransfer();
     $header->setPath('@pdf/header.twig');
     $header->setType(PdfConfig::TEMPLATE_TYPE_TWIG);
     $header->setParameter([]);
     $footer = new PdfTemplateTransfer();
     $footer->setPath('@pdf/footer.twig');
     $footer->setType(PdfConfig::TEMPLATE_TYPE_TWIG);
     $footer->setParameter([]);
     $pdf->setName('test');
     $pdf->setContent($content);
     $pdf->setHeader($header);
     $pdf->setFooter($footer);
     $pdf->setOptions(['Margin' => '1.5cm', 'HeaderHeight' => '5cm', 'FooterHeight' => '5cm']);
     $output = $this->getFacade()->outputPdfFile($pdf);
     return $this->streamedResponse(function () use($output) {
         echo $output;
     }, 200, ['Content-Type' => 'application/pdf']);
 }
 /**
  * @param \Generated\Shared\Transfer\InvoiceTransfer $invoiceTransfer
  * @param array $parameter
  *
  * @return \Generated\Shared\Transfer\PdfTemplateTransfer
  */
 protected function createFooterTemplate(InvoiceTransfer $invoiceTransfer, array $parameter)
 {
     $footerTemplate = new PdfTemplateTransfer();
     $footerTemplate->setPath($this->getFooterPath($invoiceTransfer));
     $footerTemplate->setParameter($parameter);
     $footerTemplate->setType(PdfConfig::TEMPLATE_TYPE_TWIG);
     return $footerTemplate;
 }