Easily generate PDF documents from HTML using Laravel Html2Pdf
A simple package for easily generate PDF documents from HTML.
Basic Usage
To create PDF add something like this to one of your controllers.
use NahidulHasan\Html2pdf\Facades\Pdf;
$document = Pdf::generatePdf('<h1>Test</h1>');
You can also create PDF from directly calling laravel blade file . Suppose you have a mail template named greeting in view/mails folder and want to send parameter then you have to call generatePdf method as described in below
<!-- mail template stored in resources/views/mails/greeting.blade.php -->
$document = Pdf::generatePdf(view('mails.greeting', ['name' => 'James', 'testVar' => 'demo']));
Now If you want to send mail to your client attaching pdf then you can follow this code
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('[email protected]')
->view('mails.demo')
->attachData($document, 'Invoice.pdf');
}
Link:
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 5 Laravel 5.5 Laravel 5.4 Laravel 5.6 Laravel 5.3 Intermediate