PHP Classes
elePHPant
Icontem

Laravel and PHP HTML to PDF converter: Generate PDF documents from HTML using wkhtmltopdf

Recommend this page to a friend!
  Info   View files Documentation   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2018-04-27 (5 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 142 This week: 1All time: 8,684 This week: 433Up
Version License PHP version Categories
laravel-html2pdf 1.0.0The PHP License5HTML, PHP 5, Files and Folders, Unix
Description Author

This package can generate PDF documents from HTML using wkhtmltopdf.

It can take a HTML text string and converts it to a PDF document using the wkhtmltopdf by executing it under X-Windows environment that runs on a virtual image buffer on memory.

It does not require a graphics card for you to see the document on a screen to render the PDF document.

The generated PDF document is served for download as the output of the current script that is being executed.

Although the package was meant to be run using Laravel, it can be used without requiring that framework to be installed.

  Performance   Level  
Name: Nahidul Hasan <contact>
Classes: 2 packages by
Country: Bangladesh Bangladesh
Age: ???
All time rank: 367547 in Bangladesh Bangladesh
Week rank: 345 Up9 in Bangladesh Bangladesh Up
Innovation award
Innovation award
Nominee: 1x

Details

Laravel-Html2Pdf

Latest Stable Version Total Downloads Latest Unstable Version License

> A Simple package for easily generating PDF documents from HTML.This package is specially for laravel but you can use this without laravel.

Installation

Install wkhtmltopdf

This was tested on:

  • Ubuntu 14.04 x64
  • Ubuntu 16.04 x64
sudo apt-get update
sudo apt-get install xvfb libfontconfig wkhtmltopdf

For docker

RUN apt-get update && apt-get install xvfb libfontconfig wkhtmltopdf

Upddate Composer

composer require nahidulhasan/html2pdf

If laravel version < 5.5, add the ServiceProvider to the providers array in config/app.php

NahidulHasan\Html2pdf\Html2pdfServiceProvider::class,

You can optionally use the facade for shorter code. Add this to your facades:

'Pdf'  => NahidulHasan\Html2pdf\Facades\Pdf::class,

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('username@gmail.com')
                ->view('mails.demo')
                ->attachData($document, 'Invoice.pdf');
}
  

Other Usage

It is also possible to use the following methods :


Running without Laravel

You can use this library without using Laravel.

Example:

use NahidulHasan\Html2pdf\Pdf;

$obj = new Pdf();
$document = $obj->generatePdf('<h1>Test</h1>');

License

Html2PDF for Laravel is open-sourced software licensed under the MIT license

  Files folder image Files  
File Role Description
Files folder imagesrc (2 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageFacades (1 file)
  Plain text file Html2pdfServiceProvider.php Class Class source
  Plain text file Pdf.php Class Class source

  Files folder image Files  /  src  /  Facades  
File Role Description
  Plain text file Pdf.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:142
This week:1
All time:8,684
This week:433Up