如何使用Laravel pdf库在php中下载pdf文件?
所以这在中有很好的记录,但我不能让它工作。考虑以下事项:如何使用Laravel pdf库在php中下载pdf文件?,laravel,pdf,laravel-5.6,Laravel,Pdf,Laravel 5.6,所以这在中有很好的记录,但我不能让它工作。考虑以下事项: $pdf = PDF::loadView('modules.efapreports.pdf.invoice', [ 'invoiceData' => $this->collection, 'organization' => $organization, 'invoiceNumber' => $this->formFields['invoice_nu
$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文件吗?您可以使用包dompdf来解决与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();