如何使用LaravelPDF库下载php中的pdf文件?



所以这在库中有很好的记录,但我无法让它工作。请考虑以下事项:

$pdf = PDF::loadView('modules.efapreports.pdf.invoice', [
'invoiceData'   => $this->collection,
'organization'  => $organization,
'invoiceNumber' => $this->formFields['invoice_number'],
'invoiceDate'   => $this->formFields['invoice_date'],
'dueDate'       => $this->formFields['due_date'],
'payementTerms' => $this->formFields['payment_terms'],
'gst'           => 1.05,
]);
$pdf->save(storage_path(
'efapinvoices/' . $this->getPath() .'/'. $this->getFileName() . $this->getExtension()
));
$pdf->download(storage_path(
'efapinvoices/' . $this->getPath() .'/'. $this->getFileName() . $this->getExtension()
));

这会完美地保存它,但不会下载它。我必须加载 pdf 文件吗?

return PDF::loadView('modules.efapreports.pdf.invoice', [
'invoiceData'   => $this->collection,
'organization'  => $organization,
'invoiceNumber' => $this->formFields['invoice_number'],
'invoiceDate'   => $this->formFields['invoice_date'],
'dueDate'       => $this->formFields['due_date'],
'payementTerms' => $this->formFields['payment_terms'],
'gst'           => 1.05,
])->download();

您可以使用 Package dompdf 来解决与 pdf 相关的问题。 https://packagist.org/packages/dompdf/dompdf

最新更新