Пример #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 \Generated\Shared\Transfer\PdfTransfer $pdfTransfer
  *
  * @return \Generated\Shared\Transfer\PdfTransfer
  */
 public function convertInvoiceDocument(InvoiceTransfer $invoiceTransfer, PdfTransfer $pdfTransfer)
 {
     $invoiceTransfer = $this->addTemplateVersion($invoiceTransfer);
     $parameter = ['invoiceTransfer' => $invoiceTransfer];
     $headerTemplate = $this->createHeaderTemplate($invoiceTransfer, $parameter);
     $contentTemplate = $this->createContentTemplate($invoiceTransfer, $parameter);
     $footerTemplate = $this->createFooterTemplate($invoiceTransfer, $parameter);
     $pdfTransfer->setHeader($headerTemplate);
     $pdfTransfer->setContent($contentTemplate);
     $pdfTransfer->setFooter($footerTemplate);
     $pdfTransfer->setOptions($this->getOptions());
     return $pdfTransfer;
 }
Пример #3
0
 /**
  * @param \Generated\Shared\Transfer\PdfTransfer $pdf
  * @throws \Pav\Zed\Pdf\Business\Exception\TemplateRendererNotFoundException
  *
  * @return void
  */
 protected function setHeaderAndFooter(PdfTransfer $pdf)
 {
     $header = $pdf->getHeader();
     $footer = $pdf->getFooter();
     if ($pdf->getUseDefaultLayout()) {
         $header = $this->config->getDefaultHeader();
         $footer = $this->config->getDefaultFooter();
     }
     if ($header !== null) {
         $headerString = $this->renderTemplate($header);
         $this->pdfGenerator->setHeaderHtml($headerString);
     }
     if ($footer !== null) {
         $footerString = $this->renderTemplate($footer);
         $this->pdfGenerator->setFooterHtml($footerString);
     }
 }