Email invoice in PDF | Generate PDF in Laravel | MPDF

So many time we need to send our invoices or reports in pdf. Here I'm going to explain how to generate the pdf in Laravel. You will also learn that how to send pdf in email attachment in Laravel. Here we will be creating a dynamic view page or HTML page and then will convert that html page to pdf.

Because we are creating the pdf file in Laravel so we need to install Laravel first and here is the link to let you know how to install the Laravel.

Install Laravel:
Install laravel

I'll be generating the PDF using MPDF library. So first of all we need to install mpdf using below command. I have use 6.1 version you can change it according to your need.

Install MPDF:

Here is the route to generate the pdf file in Laravel and to email it.

Here we have InvoiceController where we are generating the pdf file using mpdf in laravel. We just assign the email data to response variable, render that email data to view. Using $mpdf object we call the function writeHTML() which generates the pdf file and the we write that generated pdf file into invoice directory. Now we can send this pdf file in mail attachment in laravel very easily. After sending the mail we delete the generated pdf file using unlink() function.



Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *