2017 © Pedro Peláez
 

library html2pdf

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

image

nahidulhasan/html2pdf

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

  • Wednesday, June 27, 2018
  • by nahidulhasan
  • Repository
  • 4 Watchers
  • 64 Stars
  • 207 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 10 Versions
  • 123 % Grown

The README.md

Laravel-Html2Pdf

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

A Simple package for easily generating PDF documents from HTML.This package is specially for laravel but you can use this without laravel., (*2)

Installation

Install wkhtmltopdf

This was tested on:, (*3)

  • 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, (*4)

NahidulHasan\Html2pdf\Html2pdfServiceProvider::class,

You can optionally use the facade for shorter code. Add this to your facades:, (*5)

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

Basic Usage

To create PDF add something like this to one of your controllers., (*6)

use NahidulHasan\Html2pdf\Facades\Pdf;

$document = Pdf::generatePdf('

Test

');

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, (*7)


$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, (*8)

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('username@gmail.com')
                ->view('mails.demo')
                ->attachData($document, 'Invoice.pdf');
}

Download pdf

Save the PDF to a file in a specific folder, and then download it, (*9)

use NahidulHasan\Html2pdf\Pdf;

$obj = new Pdf();

$html = '<html><body>'
    . '

Put your html here, or generate it with your favourite ' . 'templating system., (*10)

' . '</body></html>'; $invoice = $obj->generatePdf($html); define('INVOICE_DIR', public_path('uploads/invoices')); if (!is_dir(INVOICE_DIR)) { mkdir(INVOICE_DIR, 0755, true); } $outputName = str_random(10); $pdfPath = INVOICE_DIR.'/'.$outputName.'.pdf'; File::put($pdfPath, $invoice); $headers = [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="'.'filename.pdf'.'"', ]; return response()->download($pdfPath, 'filename.pdf', $headers);

Other Usage

It is also possible to use the following methods :, (*11)

pdf::stream('<h1>Test</h1>') Open the PDF file in browser, (*12)

Running without Laravel

You can use this library without using Laravel., (*13)

Example:, (*14)

use NahidulHasan\Html2pdf\Pdf;

$obj = new Pdf();
$document = $obj->generatePdf('

Test

');

License

Html2PDF for Laravel is open-sourced software licensed under the MIT license, (*15)

The Versions

27/06 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

by Nahidul Hasan

27/06 2018

1.2.6

1.2.6.0

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

  Sources   Download

MIT

by Nahidul Hasan

22/04 2018

1.2.5

1.2.5.0

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

  Sources   Download

MIT

by Nahidul Hasan

02/04 2018

1.2.4

1.2.4.0

This package will be generated pdf

  Sources   Download

MIT

by Nahidul Hasan

02/04 2018

1.2.3

1.2.3.0

This package will be generated pdf

  Sources   Download

MIT

by Nahidul Hasan

02/04 2018

1.2.1

1.2.1.0

This package will be generated pdf

  Sources   Download

MIT

by Nahidul Hasan

02/04 2018

1.2.2

1.2.2.0

This package will be generated pdf

  Sources   Download

MIT

by Nahidul Hasan

02/04 2018

1.2.0

1.2.0.0

This package will be generated pdf

  Sources   Download

MIT

by Nahidul Hasan

29/03 2018

1.1.0

1.1.0.0

This package will be generated pdf

  Sources   Download

MIT

by Nahidul Hasan

29/03 2018

1.0.0

1.0.0.0

This package will be generated pdf

  Sources   Download

by Nahidul Hasan