Save PDF file with Dompdf Hi,
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
Solved on this way :
return PDF::loadHTML('<h1>Test</h1> ')->save('/path//my_stored_file.pdf');
Is there anyway it can be saved in the database?
That's what I am doing right now. I want to save it to the database.
view()->share('lab',$data);
$pdf = PDF::loadView('lab.test');
return $pdf->download('test_'. $request['Id'] . '_lab.pdf');
@sghimire did it work? how do you save the pdf file to database?
@Raian14 you should not save a pdf directly to the database, but instead save the path to the pdf in the database
example:
$my_pdf_path_for_example = 'my/really/cool/path/' . str_random(25) . '.pdf';
PDF::loadHTML('<h1>Test</h1> ')->save($my_pdf_path_for_example );
$model = SomeCoolModel::find(request('id') );
$model->path_to_pdf = $my_pdf_path_for_example ;
$model->save();
return response()
->download($my_pdf_path_for_example );
Obviously this is a rough example... do as you will with it... i just threw it together really fast, so there are probably errors, but you get the concepts.
Please sign in or create an account to participate in this conversation.