PHPackages                             nahidulhasan/html2pdf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. nahidulhasan/html2pdf

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

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.

1.4(5y ago)8842.3k↓36.4%14[4 issues](https://github.com/nahidulhasan/laravel-html2pdf/issues)MITPHP

Since Mar 29Pushed 5y ago6 watchersCompare

[ Source](https://github.com/nahidulhasan/laravel-html2pdf)[ Packagist](https://packagist.org/packages/nahidulhasan/html2pdf)[ RSS](/packages/nahidulhasan-html2pdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (16)Used By (0)

Laravel-Html2Pdf
================

[](#laravel-html2pdf)

[![Latest Stable Version](https://camo.githubusercontent.com/9bddf470d7b9431b8531f3c17b7ca9b9c92b0e746ca9ad4ea51b06025b05fb4a/68747470733a2f2f706f7365722e707567782e6f72672f6e61686964756c686173616e2f68746d6c327064662f762f737461626c65)](https://packagist.org/packages/nahidulhasan/html2pdf)[![Total Downloads](https://camo.githubusercontent.com/8d295dbb811a0ee6b61f32898074d6e8fe52668441857d91076f6dae9aed088a/68747470733a2f2f706f7365722e707567782e6f72672f6e61686964756c686173616e2f68746d6c327064662f646f776e6c6f616473)](https://packagist.org/packages/nahidulhasan/html2pdf)[![Latest Unstable Version](https://camo.githubusercontent.com/cf75a5854f40176683660d65330429c20b385cbe95ee7352ae95b88d55b944d1/68747470733a2f2f706f7365722e707567782e6f72672f6e61686964756c686173616e2f68746d6c327064662f762f756e737461626c65)](https://packagist.org/packages/nahidulhasan/html2pdf)[![License](https://camo.githubusercontent.com/52a92cf9bcc887a716d1b4e305cc6a3f8c53ccd573fb834aa0146c248a51b607/68747470733a2f2f706f7365722e707567782e6f72672f6e61686964756c686173616e2f68746d6c327064662f6c6963656e7365)](https://packagist.org/packages/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.

Installation
------------

[](#installation)

#### Install wkhtmltopdf

[](#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

[](#for-docker)

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

```

#### Upddate Composer

[](#upddate-composer)

```
composer require nahidulhasan/html2pdf

```

If laravel version &lt; 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
-----------

[](#basic-usage)

To create PDF add something like this to one of your controllers.

```
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

```

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

```

### Download pdf

[](#download-pdf)

Save the PDF to a file in a specific folder, and then download it

```
use NahidulHasan\Html2pdf\Pdf;

$obj = new Pdf();

$html = ''
    . 'Put your html here, or generate it with your favourite '
    . 'templating system.'
    . '';

$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

[](#other-usage)

It is also possible to use the following methods :

`pdf::stream('Test') ` Open the PDF file in browser

### Running without Laravel

[](#running-without-laravel)

You can use this library without using Laravel.

Example:

```
use NahidulHasan\Html2pdf\Pdf;

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

```

### License

[](#license)

Html2PDF for Laravel is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~76 days

Recently: every ~160 days

Total

14

Last Release

1984d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3033344?v=4)[Nahidul Hasan](/maintainers/nahidulhasan)[@nahidulhasan](https://github.com/nahidulhasan)

---

Top Contributors

[![nahidulhasan](https://avatars.githubusercontent.com/u/3033344?v=4)](https://github.com/nahidulhasan "nahidulhasan (49 commits)")[![mahfuz05](https://avatars.githubusercontent.com/u/523780?v=4)](https://github.com/mahfuz05 "mahfuz05 (1 commits)")

---

Tags

easilyhtml2pdflaravellaravel-5-packagelaravel-html2pdflaravel-packagelaravel-pdflaravel5packagepdfpdf-converterpdf-generationwkhtmltopdf

### Embed Badge

![Health badge](/badges/nahidulhasan-html2pdf/health.svg)

```
[![Health](https://phpackages.com/badges/nahidulhasan-html2pdf/health.svg)](https://phpackages.com/packages/nahidulhasan-html2pdf)
```

###  Alternatives

[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.2k57.6M131](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)[setasign/tfpdf

This class is a modified version of FPDF that adds UTF-8 support. The latest version is based on FPDF 1.85.

426.1M30](/packages/setasign-tfpdf)[aspera/xlsx-reader

Spreadsheet reader library for XLSX files

52742.2k5](/packages/aspera-xlsx-reader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
