public function saveInvoiceFile(Document $invoice) { require "vendor/autoload.php"; // inhibit DOMPDF's auto-loader define('DOMPDF_ENABLE_AUTOLOAD', false); //include the DOMPDF config file (required) require 'vendor/dompdf/dompdf/dompdf_config.inc.php'; //if you get errors about missing classes please also add: require_once 'vendor/dompdf/dompdf/include/autoload.inc.php'; $docType = $invoice instanceof Document\Invoice ? Document\Invoice::TYPE_INVOICE : Document\Invoice::TYPE_CREDIT_INVOICE; try { $renderer = $this->locator->get('Zend\\View\\Renderer\\PhpRenderer'); $renderer->setVars(array('document' => $invoice, 'rows' => $invoice->getRows())); $rendered = $renderer->render('application/document/pdf/invoice'); if ($rendered) { $output_document_dir = "data/files/Document/"; $output_customer_dir = "data/files/Customer/"; $fileNameDocument = $invoice->getId() . '_' . $invoice->getPrefix() . $invoice->getDocumentNumber() . '.pdf'; $fileNameCustomer = $invoice->getCustomer()->getId() . '_' . $invoice->getPrefix() . $invoice->getDocumentNumber() . '.pdf'; $dompdf = new \DOMPDF(); $dompdf->load_html($rendered); $dompdf->render(); $output = $dompdf->output(); file_put_contents($output_document_dir . $fileNameDocument, $output); file_put_contents($output_customer_dir . $fileNameCustomer, $output); $size = filesize($output_document_dir . $fileNameDocument); $type = filetype($output_document_dir . $fileNameDocument); $this->addDocumentFile($invoice, $output_document_dir, $fileNameDocument, $type, $size, $docType); $this->customerService->addCustomerFile($invoice->getCustomer(), $invoice, $output_customer_dir, $fileNameCustomer, $type, $size, $docType); } } catch (\Exception $e) { print_r($e->getMessage()); die; } }