how can i print this pdf using dompdf controller
public function printPDF($id)
{
$order = Order::findOrFail($id);
$products = OrderedProducts::where('orderid',$id)->get();
$pdf = PDF::loadView('admin.paymentPdf', compact('order','products'));
return $pdf->stream("invoice.pdf",array("Attachment" => false));
}
its generate pdf and download the file but i want to show this page as print view.
please help
One important thing to remember is that you can't open a new tab using PHP to show the PDF. So you can work around that by using target="_blank" in your link to the PDF. This willen open the a new tab and show you the PDF
Then the second important thing is the browser settings of the user. You can see to your download response that you don't want it to be downloaded by default, but the user can configure this in the settings of the browser as well. So you don't have control over that.
In Laravel you can use something like this to achieve that
$pdf = PDF::loadView('admin.paymentPdf', compact('order','products'));
return $pdf->stream('invoice.pdf');
Note: The stream method doesn't have a second parameter! See: https://github.com/barryvdh/laravel-dompdf/blob/master/src/PDF.php#L177
Yes you can by doing something like this
use Illuminate\Http\Response;
$pdf = PDF::loadView('admin.paymentPdf', compact('order','products'));
$output = $pdf->output();
return new Response($output, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'myfilename.pdf"',
]);
Basically we're creating a new response using Laravels Response class by passing in the output of a given PDF.
Let me know if this works for you!
@BOBBYBOUWMANN - Thanks for your response.
i am Getting this error after running this code:
Error-
local.ERROR: Use of undefined constant filename - assumed 'filename'
Code-
public function downloadPDF($id)
{
$order = Order::findOrFail($id);
$products = OrderedProducts::where('orderid',$id)->get();
$pdf = PDF::loadView('admin.paymentPdf', compact('order','products'));
// return $pdf->download('invoice.pdf');
$output = $pdf->output();
return new Response($output, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline',
'filename'=>"'invoice.pdf'"]);
}
@armancs filename is not an extra key in the array. It belongs to the Content-Disposition key. If you look carefully to my example you can see that there as well!
return new Response($output, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'invoice.pdf"',
]);
Thanks For Response.
Erorr fix by removing a quotation in invoice.pdf
return new Response($output, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="invoice.pdf"',
]);
But still file downloaded when open new tab
Please sign in or create an account to participate in this conversation.