Save PDF file with Dompdf
Asked Answered
C

4

11

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

Consequence answered 3/9, 2015 at 8:52 Comment(3)
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.Bystreet
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...Consequence
you can check this link for better solution . #60795846Devilry
N
12

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

$dompdf = new Dompdf();
$dompdf->loadHtml('<h1>hello world</h1>');
$output = $dompdf->output();
file_put_contents('filename.pdf', $output);
Necrophobia answered 29/4, 2017 at 12:34 Comment(2)
Use may use a path too: file_put_contents('/home/website/public_html/aap_path/temp/filename.pdf', $output);Winstead
Yes, you can also use an absolute path instead of a relative.Necrophobia
C
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

Consequence answered 3/9, 2015 at 9:27 Comment(0)
S
1

Try this

$pdf->load_html('<h1>Test</h1>');
$pdf->render();
$pdf->stream("data.pdf");
Slovene answered 3/9, 2015 at 9:10 Comment(0)
A
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

Aciculate answered 9/2, 2023 at 22:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.