In this article, i will let you explain how to generate pdf file from html view in laravel 5.5 application. We mostly require to generate PDF file from html view for invoice, receipt, products etc.
There are several composer packages available for pdf generate in laravel 5.5 application, However we can use "laravel-dompdf" library. laravel-dompdf provide to generate very easily using laravel balde file.
So in this example i will install laravel-dompdf package and then we will generate file using dompdf in laravel 5.5 project. So let's simply follow bellow step.
Step 1: Install laravel-dompdf Package
First of the thing is we have to install barryvdh/laravel-dompdf composer package for generate pdf file. So simply run bellow composer command for install package.
composer require barryvdh/laravel-dompdf
After install successfully above dompdf package we need to add into providers and aliases array of configuration file. So let's add following way:
'providers' => [
'aliases' => [
'PDF' => Barryvdh\DomPDF\Facade::class,
Step 2: Add Test Route
Now we will create new test route for download pdf and we will write code for download pdf using DomPDF library. So let's add following route:
Step 3: Add Controller Method
In third step we need to add downloadPDF() on HomeController file. So there we will write generate pdf file code, so add bellow method on home controller:
class HomeController extends Controller
public function downloadPDF()
$pdf = PDF::loadView('pdfView');
Step 4: add pdfView.blade.php file
In the last step, we have to create pdfView.blade.php view blade file. In this file we have to just write some html table code. So let's create blade file and put bellow code:
border:1px solid black;
border:1px solid black;
<h2>Load PDF File</h2>
Now you are ready to run full example.
I hope you found your best solution...
Do you like below Tutorials ?
- Laravel generate random unique string example
- Laravel - chmod(storage/oauth-private.key): Operation failed: Operation not permitted
- Laravel 7.x and 6.x datatables example from scratch
- How to compress PNG image using pngquant in PHP?
- Laravel 7.x and 6.x Chart example using Charts Package
- Guzzle http client GET and POST request example in Laravel 5
- Laravel schema default current timestamp value example
- Laravel 7.x and 6.x Get Site URL Examples