【问题标题】:Wkhtmltopdf unable to use the relative path for save() in Laravel 4Wkhtmltopdf 无法在 Laravel 4 中使用 save() 的相对路径
【发布时间】:2015-06-30 12:52:25
【问题描述】:

我正在使用 PDF Snappy 从 Laravel 4 中的视图生成 PDF 文件。

我可以使用 download() 毫无问题地使用此代码,并且文件已生成并且我可以保存它:

$pdf = PDFSnappy::loadView($pdfView, $dataForPDF);
return $pdf->download( 'invoice.pdf' ); 

但是,当我尝试将 save() 与此代码一起使用时:

$pathToFile = "invoices/2015/full/invoice.pdf";

$pdf = PDFSnappy::loadView($pdfView, $dataForPDF);
return $pdf->save( $pathToFile );

我收到此错误消息:

Object of class Barryvdh\\Snappy\\PdfWrapper could not be converted to string

如果我尝试这样的事情:

$pathToFile = url() . '/' . "invoices/2015/full/invoice.pdf";

$pdf = PDFSnappy::loadView($pdfView, $dataForPDF);
return $pdf->save( $pathToFile );

我收到此错误消息:

The output file's directory http://laravel.dev/invoices/2015/full/ could not be created.

我在 Windows 上使用 WAMP,这可能是个问题吗?

如何将文件保存到 invoices/2015/full/ 内 Laravel 中的 /public 文件夹中?

【问题讨论】:

    标签: php laravel laravel-4 pdf-generation wkhtmltopdf


    【解决方案1】:

    好的,看来解决方案是从这里删除return

    return $pdf->save( $pathToFile );

    并改用此代码:

    $pdf->save( $pathToFile );

    并且不需要额外的 url 调整,您可以使用相对“公共”路径来保存您的 pdf。

    希望它对未来的人有所帮助;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多