Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save PDF file with Dompdf

using Dompdf to store data in pdf file:

This function work fine :

$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1> ');
return $pdf->stream();

Now,when try

$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML('<h1>Test</h1> ');
file_put_contents("test.pdf", $pdf->output());

Get error:

file_put_contents(test.pdf): failed to open stream: Permission denied

Do I need to create some extra folder for saving file or something ?

Tnx, P

like image 725
pavlenko Avatar asked Sep 03 '15 08:09

pavlenko


People also ask

How do I change the page size of a PDF in Dompdf?

$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait'); You can use 'letter', 'legal', 'A4', etc.. With dompdf 0.6 you can also use the CSS @page rule to set your page size/orientation. e.g. @page { size: a4 landscape; } or @page { size: 360pt 360pt; } .

How can I create multiple PDF using Dompdf in PHP?

If you wish to generate multiple pdf files in one go, you must save the documents in the server and then use JavaScript for-loop inside AJAX and pass the files one by one in the background. This will not kill the loop process since AJAX runs in the background.


1 Answers

To save the generated pdf to a file, use output(), i.e.:

$dompdf = new Dompdf();
$dompdf->loadHtml('<h1>hello world</h1>');
$output = $dompdf->output();
file_put_contents('filename.pdf', $output);
like image 165
Pedro Lobito Avatar answered Oct 14 '22 22:10

Pedro Lobito