after generating the PDF file, please how can i save it to a path and send it through email instead of download directly... thanks
Example using the facade and a view and the laravel storage_path helper function:
$pdf = PDF::loadView('some.view.name', ['someVariableName' => 'some value']);
$pdf->save(storage_path('some-folder/some-subfolder/some-filename.pdf'));
To send this file as an attachment via E-mail there are of course ways:
http://laravel.com/docs/5.1/mail#attachments
Additional info for saving using the Storage facade and Spatie Media Library:
Using the Storage facade:
/** @var \Barryvdh\Snappy\PdfWrapper $pdf */
$pdf = App::make('snappy.pdf.wrapper');
// The view data.
$data = ['...'];
// Generate the PDF output.
$output = $pdf->loadView('reports.print', $data)->output();
// The file name.
$name = 'Report.pdf';
// Get our disk to store the PDF in.
$disk = Storage::disk('public');
// Save the file with the PDF output.
if ($disk->put($name, $output)) {
// Successfully stored. Return the full path.
return $disk->path($name);
}
Using Spatie Media Library:
// Locate the report.
$report = Report::find(1);
/** @var \Barryvdh\Snappy\PdfWrapper $pdf */
$pdf = App::make('snappy.pdf.wrapper');
// The view data.
$data = ['...'];
// Generate the PDF output.
$output = $pdf->loadView('reports.print', $data)->output();
// Make the file name.
$name = Str::slug($report->title).'.pdf';
// Get our disk to store the PDF in.
$disk = Storage::disk('public');
// Save the file with the PDF output.
if ($disk->put($name, $output)) {
// Successfully stored. We'll move it into our media
// collection and save it to our "report" model.
$report->addMedia($disk->path($name))->toMediaCollection('pdf');
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy.
If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.
Most helpful comment
Example using the facade and a view and the laravel storage_path helper function:
To send this file as an attachment via E-mail there are of course ways:
http://laravel.com/docs/5.1/mail#attachments