PHPackages                             ashik/pdf - 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. ashik/pdf

ActiveLibrary

ashik/pdf
=========

A custom Laravel package for generating PDFs using mPDF with Facades and a Wrapper

v1.0.0(1y ago)050MITPHPPHP ^8.3

Since Dec 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ashikahmed-bd/Laravel-Pdf)[ Packagist](https://packagist.org/packages/ashik/pdf)[ RSS](/packages/ashik-pdf/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel PDF: mPDF wrapper for Laravel 7.0
=========================================

[](#laravel-pdf-mpdf-wrapper-for-laravel-70)

> Easily generate PDF documents from HTML right inside of Laravel using this mPDF wrapper.

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

[](#installation)

Require this package in your `composer.json` or install it by running:

```
composer require ashik/pdf

```

> Note: This package supports auto-discovery features of Laravel 5.5+, You only need to manually add the service provider and alias if working on Laravel version lower then 7.0

To start using Laravel, add the Service Provider and the Facade to your `config/app.php`:

```
'providers' => [
	// ...
	Ashik\Pdf\PdfServiceProvider::class
]
```

```
'aliases' => [
	// ...
	'Pdf' => Ashik\Pdf\Facades\Mpdf::class
]
```

Now, you should publish package's config file to your config directory by using following command:

```
php artisan vendor:publish --tag=pdf-config

```

Basic Usage
-----------

[](#basic-usage)

To use Laravel PDF add something like this to one of your controllers. You can pass data to a view in `/resources/views`.

```
use Ashik\Pdf\Facades\Pdf;

class ReportController extends Controller
{
    public function viewPdf()
    {
        $pdf = Pdf::loadView('pdf.document', [
            'foo' => 'bar'
        ]);
        return $pdf->stream('document.pdf');
    }
}
```

Config
------

[](#config)

You can use a custom file to overwrite the default configuration. Just execute `php artisan vendor:publish --tag=pdf-config` or create `config/pdf.php` and add this:

```
return [
    'mode'                       => '',
    'format'                     => 'A4',
    'default_font_size'          => '12',
    'default_font'               => 'sans-serif',
    'margin_left'                => 10,
    'margin_right'               => 10,
    'margin_top'                 => 10,
    'margin_bottom'              => 10,
    'margin_header'              => 0,
    'margin_footer'              => 0,
    'orientation'                => 'P',
    'title'                      => 'Laravel mPDF',
    'author'                     => '',
    'watermark'                  => '',
    'show_watermark'             => false,
    'show_watermark_image'       => false,
    'watermark_font'             => 'sans-serif',
    'display_mode'               => 'fullpage',
    'watermark_text_alpha'       => 0.1,
    'watermark_image_path'       => '',
    'watermark_image_alpha'      => 0.2,
    'watermark_image_size'       => 'D',
    'watermark_image_position'   => 'P',
    'custom_font_dir'            => '',
    'custom_font_data'           => [],
    'auto_language_detection'    => false,
    'temp_dir'                   => storage_path('app'),
    'pdfa'                       => false,
    'pdfaauto'                   => false,
    'use_active_forms'           => false,
];
```

To override this configuration on a per-file basis use the fourth parameter of the initializing call like this:

```
// ...

PDF::loadView('pdf', $data, [], [
    'title' => 'Another Title',
])->save($pdfFilePath);
```

Included Fonts
--------------

[](#included-fonts)

By default you can use all the fonts [shipped with Mpdf](https://mpdf.github.io/fonts-languages/available-fonts-v6.html).

Custom Fonts
------------

[](#custom-fonts)

You can use your own fonts in the generated PDFs. The TTF files have to be located in one folder, e.g. `resources/fonts/`. Add this to your configuration file (`/config/pdf.php`):

```
return [
    'custom_font_dir'  => base_path('resources/fonts/'), // don't forget the trailing slash!
    'custom_font_data' => [
        'examplefont' => [ // must be lowercase and snake_case
            'R'  => 'ExampleFont-Regular.ttf',    // regular font
            'B'  => 'ExampleFont-Bold.ttf',       // optional: bold font
            'I'  => 'ExampleFont-Italic.ttf',     // optional: italic font
            'BI' => 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font
        ]
      // ...add as many as you want.
    ]
];
```

Now you can use the font in CSS:

```
body {
  font-family: 'examplefont', sans-serif;
}
```

Chunk HTML
----------

[](#chunk-html)

For big HTML you might get `Uncaught Mpdf\MpdfException: The HTML code size is larger than pcre.backtrack_limit xxx` error, or you might just get [empty or blank result](https://mpdf.github.io/troubleshooting/known-issues.html#blank-pages-or-some-sections-missing). In these situations you can use chunk methods while you added a separator to your HTML:

```
//....
use Ashik\Pdf\Facades\Pdf;
class ReportController extends Controller
{
    public function generate_pdf()
    {
        $data = [
            'foo' => 'hello 1',
            'bar' => 'hello 2'
        ];
        $pdf = Pdf::chunkLoadView('', 'pdf.document', $data);
        return $pdf->stream('document.pdf');
    }
}
```

```

    Hello World

        {{ $foo }}

        {{ $bar }}

```

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

528d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc0cd81a3c8572afcd33e9efb934e419981ebd1d815b75fe9dc070e072ef81a7?d=identicon)[ashikahmedbd](/maintainers/ashikahmedbd)

---

Top Contributors

[![ashik-ahmed-bd](https://avatars.githubusercontent.com/u/108466148?v=4)](https://github.com/ashik-ahmed-bd "ashik-ahmed-bd (1 commits)")

### Embed Badge

![Health badge](/badges/ashik-pdf/health.svg)

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

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

26.2k161.6k7](/packages/bagisto-bagisto)[krayin/laravel-crm

Krayin CRM

22.0k32.8k1](/packages/krayin-laravel-crm)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[carlos-meneses/laravel-mpdf

Laravel Mpdf: Using Mpdf in Laravel to generate Pdfs.

4403.1M7](/packages/carlos-meneses-laravel-mpdf)[kartik-v/yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.

1605.5M84](/packages/kartik-v-yii2-mpdf)[contributte/pdf

Pdf response extension for Nette Framework

43967.8k2](/packages/contributte-pdf)

PHPackages © 2026

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