2015-04-22 82 views
-1

我使用PDF斯納皮產生從意見PDF文件Laravel 4Wkhtmltopdf無法使用Laravel的保存()的相對路徑4

我可以使用下載使用此代碼()沒有任何問題和文件中生成,我可以將其保存:

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

然而,當我嘗試使用此代碼使用保存():

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

我收到此錯誤信息:使用WAMP

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

在Windows上我,那會是一個問題嗎?

如何將文件保存到我的/public文件夾中Laravel裏面invoices/2015/full/

回答

0

OK,這樣看來,解決方案是從這個刪除return

return $pdf->save($pathToFile);

,並使用此代碼來代替:

$pdf->save($pathToFile);

而且沒有額外的URL的調整是必要的,你可以使用你想要保存你的pdf的相對的「公共」路徑。

希望它能幫助未來的人;)