shipmentLoader = $shipmentLoader; $this->_fileFactory = $fileFactory; parent::__construct($context); } /** * Create pdf document with information about packages * * @return ResponseInterface|void */ public function execute() { $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id')); $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id')); $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment')); $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking')); $shipment = $this->shipmentLoader->load(); if ($shipment) { /** @var \Zend_Pdf $pdf */ $pdf = $this->_objectManager->create(\Magento\Shipping\Model\Order\Pdf\Packaging::class)->getPdf($shipment); return $this->_fileFactory->create( 'packingslip' . $this->_objectManager->get( \Magento\Framework\Stdlib\DateTime\DateTime::class )->date( 'Y-m-d_H-i-s' ) . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf' ); } else { $this->_forward('noroute'); } } }