Answer the question
In order to leave comments, you need to log in
How to do pdf generation and upload on the fly?
Hello. There is such a task: to generate a pdf-file on the button, and immediately give this file to the user for downloading, without saving the file on the server. If that's even possible, I don't know.
Source: laravel 5, barryvdh/laravel-dompdf package for generating pdf. Until I got to this:
$pdf = \App::make('dompdf.wrapper');
$pdf = $pdf->loadView('pdf.offer', [ 'offer' => $offer ]);
$filename = public_path().'/files/pdf/offers/'.str_slug($offer->title . '_' . $offer->id).'.pdf';
$pdf->save($filename);
return 'http://'.request()->getHost().'/files/pdf/offers/'.str_slug($offer->title . '_' . $offer->id).'.pdf';
....
success: function(data){
window.open(data);
}
....
Answer the question
In order to leave comments, you need to log in
Load not via ajax, but as src of an invisible iframe. Or submit the form with target=Your iframe.
And instead of save, do something like output, something like this
Route::post('/invoice/pdf', '[email protected]')->name('getInvoice');
<form role="form" action="{{ route('getInvoice') }}" method="post">
{{ csrf_field() }}
<input type="hidden" name="invoice_id" value="{{ $item->DocID }}">
<button type="submit" class="btn btn-link">скачать</button>
</form>
/**
* @param Request $request
*
* @return $this
*/
public function getInvoice(Request $request)
{
//валидируем
//подключаем пдф
$pdf = app('dompdf.wrapper');
//формируем пдф вью
$pdf->loadView('docs.invoice');
//возвращаем на скачивание
return $pdf->download('invoice.pdf');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question