I am making an online exam web app. Where students will log in, and there will be an exam packet. Now the packets already have questions stored in the database, I have already converted the questions into HTML to PDF format and it's available to be downloaded. The question is, how will I able to get the generated PDF to also be uploaded to the database? Because the questions for each user will be in random order, and I would like each user to continue the previous exam packet once they log in, so it doesn't regenerate again.
2条回答 默认 最新
- donglongqiao9595 2018-06-23 09:13关注
You dont need to store it in database if u already have a html template of the data that are going to be included in pdf
Step 1) Download install this package
composer require barryvdh/laravel-dompdf
Step 2) fter install pdf package for laravel then we must be configure it. just following littel thing. oprn your
config/app.php
file and set following value for providers array and aliases array'providers' => [ .... Barryvdh\DomPDF\ServiceProvider::class, ], 'aliases' => [ .... 'PDF' => Barryvdh\DomPDF\Facade::class, ],
Then run
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
Step 3) Create a route
Route::get('generate-pdf', 'PdfGenerateController@pdfview')->name('generate-pdf');
Step 4) Add the logic to download a view as pdf:
$pdf = App::make('dompdf.wrapper'); $pdf->loadHTML('<h1>Test</h1>'); return $pdf->stream();
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报