Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Pdfinvoices.php
Go to the documentation of this file.
1 <?php
8 
17 use Magento\Sales\Model\ResourceModel\Order\Invoice\CollectionFactory;
18 
22 abstract class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction
23 {
29  const ADMIN_RESOURCE = 'Magento_Sales::sales_invoice';
30 
34  protected $fileFactory;
35 
39  protected $dateTime;
40 
44  protected $pdfInvoice;
45 
54  public function __construct(
55  Context $context,
60  CollectionFactory $collectionFactory
61  ) {
62  $this->fileFactory = $fileFactory;
63  $this->dateTime = $dateTime;
64  $this->pdfInvoice = $pdfInvoice;
65  $this->collectionFactory = $collectionFactory;
66  parent::__construct($context, $filter);
67  }
68 
77  {
78  $pdf = $this->pdfInvoice->getPdf($collection);
79  $fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
80 
81  return $this->fileFactory->create(
82  sprintf('invoice%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
83  $fileContent,
85  'application/pdf'
86  );
87  }
88 }
__construct(Context $context, Filter $filter, DateTime $dateTime, FileFactory $fileFactory, Invoice $pdfInvoice, CollectionFactory $collectionFactory)
Definition: Pdfinvoices.php:54