A simple package for easily generate PDF documents from HTML.

laravel pdf

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');
}