如何使用Laravel PDF库在php中下载pdf文件?

时间:2018-09-01 00:14:11

标签: laravel pdf laravel-5.6

因此,the library中对此进行了很好的记录,但我无法使其正常工作。请考虑以下内容:

    $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文件吗?

2 个答案:

答案 0 :(得分:1)

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();

答案 1 :(得分:0)

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