Is there a way to programatically save pdf invoices to a directory on the magento server without the system attempting to download it?
I currently use the below code to generate and save the file to a directory on the server but it also attempts to download it. I just need the link which I already get as output but want to prevent the auto downloading it.
Thanks in advance.
$filename = 'pdf/Invoice-' . $invoiceCollection->getFirstItem()->getIncrementId() . '.pdf';
try{
$pdf = $this->pdfInvoice->getPdf($invoiceCollection);
$file = $this->fileFactory->create(
$filename,
$pdf->render(),
DirectoryList::MEDIA,
'application/pdf'
);
$mediaUrl = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA ) . $filename;
} catch (\Exception $e) {
$this->logger->info('Error printing invoice: ' . $e->getMessage() . ' error.');
}