New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

mralston/pdf

Laravel wrapper for generating PDF files using headless Chrome/Chromium
1,002 6
Install
composer require mralston/pdf
Latest Version:v1.0.7
PHP:^7.4.15|^8.0
Laravel:7 – 13
License:MIT
Last Updated:Oct 27, 2026
Links: GitHub  ·  Packagist
Maintainer: mralston

PDF

Introduction

A convenient way to generate PDF files in Laravel using a headless Chrome/Chromium instance.

This package is a wrapper around chrome-php/chrome.

Config

You may publish the config file as follows:

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

Usage

Here are now the basic functions of the wrapper library work:

use Mralston\Pdf\Pdf;

// Can be instantiated using a view
$pdf = Pdf::fromView('path.to.blade-template', [
    'variable1' => $value1,
    'variable2' => $value2,
]);

// Or with HTML
$html = '<html><head><title>test</title></head><body>...</body></html>';

$pdf = Pdf::fromHtml($html);

// Or from a URL
$pdf = Pdf::fromUrl('https://www.google.com/');

// The path to the Chrome executable can be adjusted (defaults to /usr/bin/chromium)
// This can also be done using the CHROME_BINARY environment variable
$pdf->setChromeBinary('/bin/chrome');

// Options can be passed to the Chrome rendering engine
$pdf->setOptions([
    'landscape' => true,
    'scale' => 0.8,
]);

// It can be instructed to emulate PhantomJS (your mileage may vary)
$pdf->emulatePhantomJs();

// The timeout can be adjusted for slow pages (defaults to 30 seconds)
$pdf->setTimeout(60);

// The PDF can be saved to disk
$pdf->save('/path/to/output.pdf');

// Or streamed to the browser
return $pdf->stream();

// Or sent to the browser as a download
return $pdf->download($filename);

Putting it all together into a (somewhat) real-world example:

use Mralston\Pdf\Pdf;
use App\Models\Invoice;
use Illuminate\Http\Response;

class InvoiceController
{
    public function downloadPdf(Invoice $invoice, string $filename): Response
    {
        return Pdf::fromView('invoices.show', [
            'invoice' => $invoice,
        ])
        ->setChromeBinary('/usr/bin/chrome')
        ->setOptions([
            'landscape' => true,
            'scale' => 0.9,
        ])
        ->setTimeout(60)
        ->download($filename);
    }
}

Security Vulnerabilities

Please e-mail security vulnerabilities directly to me.

Licence

PDF is open-sourced software licenced under the MIT license.

Related Packages

mralston/mug

Library for working with My Utility Genius API.

1,085 0
mralston/iq

Package for working with IQ CRM.

1,080 0
barryvdh/laravel-dompdf

A DOMPDF Wrapper for Laravel

133,038,324 7,299
carlos-meneses/laravel-mpdf

Laravel Mpdf: Using Mpdf in Laravel to generate Pdfs.

4,088,448 439
elibyy/tcpdf-laravel

tcpdf support for Laravel 6, 7, 8, 9, 10, 11

3,349,194 357

Version History

Version Released PHP Laravel License
v1.0.7 ^7.4.15|^8.0 ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
v1.0.6 ^7.4.15|^8.0 ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
v1.0.5 ^7.4.15|^8.0 ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0|^13.0 MIT
v1.0.4 ^7.4.15|^8.0 ^7.0|^8.0|^9.0|^10.0|^11.0|^12.0 MIT
v1.0.3 ^7.4.15|^8.0 ^7.0|^8.0|^9.0|^10.0|^11.0 MIT