8

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

pavlenko
  • 625
  • 2
  • 11
  • 30
  • Quiet simple, you don't have the sufficient rights to write to the folder / directory? Check that you're webuser has the required read/write to folder and file. – Epodax Sep 03 '15 at 08:54
  • Hi,tnx for time ! That is ok, I alsto try with specific path, same error... But I can't find in documentation in which folder will be this file saved, so to know what perrmision to change... – pavlenko Sep 03 '15 at 08:59
  • you can check this link for better solution . https://stackoverflow.com/questions/60795346/how-to-save-dompdf-file-to-storage-and-name-the-file-dynamicly-in-laravel/74942859#74942859 – pankaj Dec 28 '22 at 16:47

4 Answers4

9

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);
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
2

This resolve problem :

  return PDF::loadHTML('<h1>Test</h1> ')->save('path-/my_stored_file.pdf');

This question help:

dompdf: loading html files to render, doesn't work

Tnx, P

Community
  • 1
  • 1
pavlenko
  • 625
  • 2
  • 11
  • 30
1

Try this

$pdf->load_html('<h1>Test</h1>');
$pdf->render();
$pdf->stream("data.pdf");
Keval Rathi
  • 978
  • 6
  • 21
0

You should check the permissions of the folder. (0777) enter image description here

    $pdf->load_html('<h1>Test</h1>');
    $pdf->render();
    $output = $pdf->output();
    file_put_contents('./historialCartera/prueba.pdf', $output);

enter image description here

Mauricio Romero
  • 161
  • 1
  • 2