how to save pdf in directory laravel 4.2 using dompdf

4.9k views Asked by At

i have followed this example laravel-4-create-pdf-use-dompdf:

i want to save pdf in directory not pdf preview in the browser.

My current code:

    $pdf = \App::make('dompdf');
    $pdf->loadHTML('<h1>Hello World!!</h1>');
    return $pdf->stream("order_email.pdf");

but what this code is doing, it shows my "Hello World" text as PDF in the browser but not saving "order_email.pdf" anywhere in my working directory.

2

There are 2 answers

1
BrianS On BEST ANSWER

Dompdf's stream() method always sends to the browser. If you want to capture the output and save to a file you should use the output() method instead.

$pdf = \App::make('dompdf');
$pdf->loadHTML('<h1>Hello World!!</h1>');
file_put_contents("order_email.pdf", $pdf->output());
1
Muhammad On

i also found one more method to save it.

$pdf->save('order_email.pdf');