PHPackages                             mavorion/laravel-pdf-legacy - 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. mavorion/laravel-pdf-legacy

ActiveLibrary

mavorion/laravel-pdf-legacy
===========================

Create PDFs in Laravel apps

1.0.0(today)01↑2900%MITPHP ^7.1CI passing

Since Jul 28Pushed todayCompare

[ Source](https://github.com/MavorionDeveloper/laravel-pdf)[ Packagist](https://packagist.org/packages/mavorion/laravel-pdf-legacy)[ Docs](https://github.com/SandipGhimire/laravel-pdf)[ RSS](/packages/mavorion-laravel-pdf-legacy/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (7)Versions (3)Used By (0)

Create PDFs in Laravel apps
===========================

[](#create-pdfs-in-laravel-apps)

[![Latest Version on Packagist](https://camo.githubusercontent.com/eb4451b8f7caf7ea5c959a13fc27356ae4734b2e4b4681bf1f561cdc16a69b2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d7064662e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-pdf)[![GitHub Tests Action Status](https://github.com/spatie/laravel-pdf/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-pdf/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://github.com/spatie/laravel-pdf/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/spatie/laravel-pdf/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/46231fac7df06cfbc7a5c613a227117b1206aa6abc0b6e7e8153b7d51cd2c1e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d7064662e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-pdf)

This package provides a simple way to create PDFs in Laravel apps. It supports multiple drivers: [Browsershot](https://spatie.be/docs/browsershot) (Chromium), [Gotenberg](https://gotenberg.dev) (Docker-based), [Cloudflare Browser Run](https://developers.cloudflare.com/browser-run/), [WeasyPrint](https://doc.courtbouillon.org/weasyprint/stable/) (Python-based), [DOMPDF](https://github.com/dompdf/dompdf) (pure PHP), and [chrome-php/chrome](https://github.com/chrome-php/chrome) (Chromium). You can use modern CSS features like grid and flexbox with the Chromium-based drivers, use WeasyPrint for excellent CSS Paged Media support, or choose DOMPDF for a zero-dependency setup.

> **`legacy-php71` branch note:** this branch is a manual backport targeting **PHP 7.1 / Laravel 5.2-5.5**, for projects that can't run the PHP 8.2+ main branch. It ships **only the Browsershot driver** (spatie/browsershot pinned to `^3.26`, the newest release whose `symfony/process` requirement still overlaps with Laravel 5.5's). Dropped compared to `main`: every other driver, PDF encryption/password-protection (`->encrypt()`), `->scale()`, `->tagged()`, AWS Lambda (`->onLambda()`), and non-`mm` units for `->margins()`/`->paperSize()` - all of those throw `CouldNotGeneratePdf` if called, since either the dependency has no PHP 7.1-compatible release or this old Browsershot version doesn't support the option. See `config/laravel-pdf.php` and `src/Exceptions/CouldNotGeneratePdf.php` for specifics. This branch is not maintained in lockstep with `main`.
>
> `PdfBuilder` doesn't implement `Illuminate\Contracts\Support\Responsable` (that interface doesn't exist before Laravel 5.5, and this branch supports 5.2+) - so `return Pdf::view(...)->download();` from a controller won't auto-convert to a response. Call `->toResponse(request())` explicitly instead (see the example below). `->saveQueued()` needs `Illuminate\Foundation\Bus\PendingDispatch`, which doesn't exist before Laravel 5.3 either - queued generation isn't available on 5.2.

Here's a quick example:

```
use Mavorion\LaravelPdf\Facades\Pdf;

Pdf::view('pdfs.invoice', ['invoice' => $invoice])
    ->format('a4')
    ->save('invoice.pdf')
```

This will render the Blade view `pdfs.invoice` with the given data and save it as a PDF file.

You can also return the PDF as a response from your controller:

```
use Mavorion\LaravelPdf\Facades\Pdf;

class DownloadInvoiceController
{
    public function __invoke(Invoice $invoice)
    {
        return Pdf::view('pdfs.invoice', ['invoice' => $invoice])
            ->format('a4')
            ->name('your-invoice.pdf')
            ->toResponse(request());
    }
}
```

You can use also test your PDFs:

```
use Mavorion\LaravelPdf\Facades\Pdf;

it('can render an invoice', function () {
    Pdf::fake();

    $invoice = Invoice::factory()->create();

    $this->get(route('download-invoice', $invoice))
        ->assertOk();

    Pdf::assertRespondedWithPdf(function (PdfBuilder $pdf) {
        return $pdf->contains('test');
    });
});
```

Laravel Boost
-------------

[](#laravel-boost)

This package ships with a [Laravel Boost](https://laravel.com/docs/12.x/boost) skill. After installing the package, run `php artisan boost:install` to register the skill. This will help AI agents in your project generate correct PDF code.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/9b85c24f6587b06e227bbdb00eb7dca971669a1311d2a94c2ea966d25c03cf09/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d7064662e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-pdf)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Documentation
-------------

[](#documentation)

All documentation is available [on our documentation site](https://spatie.be/docs/laravel-pdf).

Testing
-------

[](#testing)

For running the testsuite, you'll need to have Puppeteer installed. Pleaser refer to the Browsershot requirements [here](https://spatie.be/docs/browsershot/v4/requirements). Usually `npm -g i puppeteer` will do the trick.

Additionally, you'll need the `pdftotext` CLI which is part of the poppler-utils package. More info can be found in in the [spatie/pdf-to-text readme](https://github.com/spatie/pdf-to-text?tab=readme-ov-file#requirements). Usually `brew install poppler-utils` will suffice.

Finally run the tests with:

```
composer test
```

Production deployment (`legacy-php71` branch)
---------------------------------------------

[](#production-deployment-legacy-php71-branch)

Browsershot doesn't render PDFs itself - it shells out to Node, which drives a real Chrome/Chromium. Both have to be present on whatever host actually runs PHP-FPM, not just wherever `composer install` was run.

### Requirements

[](#requirements)

RequirementVersionNotesPHP7.1With `ext-json`. EOL upstream - see Security below.Node.js**&gt;= 10.18.1**Anything older can't run the puppeteer version this branch needs.puppeteer**exactly `13.7.0`**, installed globally via npmSee the warning below - do not take latest.Chrome or Chromiumany current releaseReferenced by path in config, not downloaded by puppeteer.System libraries~20 packagesNSS, GTK, X11, ALSA - see the install commands below.spatie/browsershot`^3.26`Already pinned in this branch's `composer.json`.> **Pin puppeteer to `13.7.0` - do not install latest.** Puppeteer 22+ changed `page.pdf()` and `page.screenshot()` to return a `Uint8Array` instead of a Node `Buffer`. Browsershot's bundled `browser.js` driver script calls `.toString('base64')` on the result - on a `Buffer` that produces valid base64; on a `Uint8Array` it silently returns a comma-joined list of decimal byte values instead, with **no error thrown**. Anything that reads PDF content back into PHP (`->base64()`, `->meta()`) ends up corrupted. File-based `->save($path)` is unaffected, since Chrome writes that file directly regardless of the bug.

### Install (Docker)

[](#install-docker)

Recommended: bake everything into the image so it's self-contained.

```
FROM php:7.1-fpm

# --- Node.js LTS ---
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
RUN apt-get install -y nodejs

# --- Google Chrome + everything headless Chrome links against ---
RUN curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb https://dl.google.com/linux/chrome/deb/ stable main" \
      > /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update && apt-get install -y \
      google-chrome-stable fonts-liberation libasound2 \
      libatk-bridge2.0-0 libatk1.0-0 libcairo2 libcups2 libdbus-1-3 \
      libdrm2 libexpat1 libgbm1 libglib2.0-0 libgtk-3-0 libnspr4 \
      libnss3 libpango-1.0-0 libx11-6 libxcomposite1 libxdamage1 \
      libxext6 libxfixes3 libxkbcommon0 libxrandr2 xdg-utils \
    && rm -rf /var/lib/apt/lists/*

# --- puppeteer, pinned, using system Chrome instead of its own download ---
ENV PUPPETEER_SKIP_DOWNLOAD=true
RUN npm install -g puppeteer@13.7.0

# run as a real non-root user so Chrome's own sandbox can initialize
RUN useradd -m -u 1000 app
USER app
```

### Install (bare metal / VM)

[](#install-bare-metal--vm)

Same dependencies, installed on the host directly. PHP 7.1 no longer ships in current Ubuntu/Debian repos, so it comes from a third-party PPA.

```
# PHP 7.1 (EOL upstream, needs a maintained third-party repo)
sudo add-apt-repository ppa:ondrej/php   # Ubuntu; use packages.sury.org on Debian
sudo apt-get update
sudo apt-get install -y php7.1-fpm php7.1-cli php7.1-mbstring php7.1-xml php7.1-curl php7.1-zip php7.1-sqlite3

# Node.js LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash -
sudo apt-get install -y nodejs

# Google Chrome + its shared-library dependencies
curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
echo "deb https://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list
sudo apt-get update && sudo apt-get install -y google-chrome-stable \
  fonts-liberation libasound2 libatk-bridge2.0-0 libatk1.0-0 libcairo2 \
  libcups2 libdbus-1-3 libdrm2 libexpat1 libgbm1 libglib2.0-0 libgtk-3-0 \
  libnspr4 libnss3 libpango-1.0-0 libx11-6 libxcomposite1 libxdamage1 \
  libxext6 libxfixes3 libxkbcommon0 libxrandr2 xdg-utils

# puppeteer, pinned, no bundled Chromium download
sudo PUPPETEER_SKIP_DOWNLOAD=true npm install -g puppeteer@13.7.0
```

If Chrome fails with `error while loading shared libraries: lib.so: cannot open shared object file`, that library is still missing - run `ldd $(which google-chrome-stable)` to see exactly what's unresolved. Package names differ on RHEL/Alma/Fedora (`nss`, `atk`, `at-spi2-atk`, `cups-libs`, `libXcomposite`, etc.).

### Using nvm instead of a system-wide Node install

[](#using-nvm-instead-of-a-system-wide-node-install)

If Node is managed per-user via nvm (common when a server already runs an older Node for other apps), install a second version rather than upgrading the existing one:

```
nvm install 20   # any LTS >= 10.18.1
nvm use 20
PUPPETEER_SKIP_DOWNLOAD=true npm install -g puppeteer@13.7.0
```

Then point the config at the **resolved absolute paths** (`nvm which 20` / `npm root -g`), not at `nvm`/`node` on `PATH`:

```
LARAVEL_PDF_NODE_BINARY=/home//.nvm/versions/node/v20.20.2/bin/node
LARAVEL_PDF_NODE_MODULES_PATH=/home//.nvm/versions/node/v20.20.2/lib/node_modules
```

This matters because PHP-FPM's non-interactive process never sources `nvm.sh` - `node`/`npm` won't be on its `PATH` and the `nvm` shell function won't exist, so a bare `LARAVEL_PDF_NODE_BINARY=node` silently fails. Setting the explicit `NODE_MODULES_PATH` also skips the `npm root -g` shell-out Browsershot would otherwise run on every single PDF render.

### Configuration

[](#configuration)

All of the following read from `config/laravel-pdf.php`, already wired to these env vars - nothing in the package needs editing.

VariablePurposeTypical production value`LARAVEL_PDF_DRIVER`Which driver builds the PDF`browsershot` (only driver on this branch)`LARAVEL_PDF_CHROME_PATH`Absolute path to the Chrome/Chromium binary`/usr/bin/google-chrome-stable``LARAVEL_PDF_NODE_BINARY`Override if `node` isn't on PHP-FPM's `PATH`absolute path, see nvm note above`LARAVEL_PDF_NODE_MODULES_PATH`Skips the `npm root -g` shell-out at request timeabsolute path, see nvm note above`LARAVEL_PDF_NO_SANDBOX`Adds Chrome's `--no-sandbox` flag`false` - only `true` if running as root in a container (see Security)### Security

[](#security)

- **PHP 7.1 receives no security patches** (EOL since December 2019). Keep this service behind a reverse proxy, scoped to only the routes it needs, and track a real upgrade path off PHP 7.1 - this guide doesn't change that fact.
- **Rendering untrusted HTML is a real attack surface.** Headless Chrome fetches anything referenced by the HTML it's given - remote images, stylesheets, fonts - and can be pointed at internal network addresses (SSRF) if the input isn't trusted. Sanitize any user-supplied HTML or view data before rendering it to PDF.
- **`--no-sandbox` is a trade-off, not a formality.** It disables a real isolation boundary between a compromised renderer process and the host. Prefer running the service as a genuine non-root user (see the Dockerfile above) so Chrome's sandbox can initialize normally, instead of reaching for this flag.
- Give the render process a memory ceiling and a timeout (`->timeout($seconds)` on the builder, plus your process supervisor's memory limit). A stuck or oversized headless Chrome instance is the most common way this kind of service falls over.

### Verifying the setup

[](#verifying-the-setup)

```
php -v                                                        # 7.1.x
node -v                                                       # >= 10.18.1
npm ls -g puppeteer                                           # 13.7.0
google-chrome-stable --headless --disable-gpu --version       # no missing-library errors
```

Then hit a real PDF-generating route and confirm the response starts with `%PDF-` and, separately, that a `->base64()` call also decodes to something starting with `%PDF-` (confirms the puppeteer pin, not just file-based saves which work even with the buggy version).

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

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

0d ago

### Community

Maintainers

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

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (275 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (22 commits)")[![ArielMejiaDev](https://avatars.githubusercontent.com/u/31971074?v=4)](https://github.com/ArielMejiaDev "ArielMejiaDev (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (10 commits)")[![A909M](https://avatars.githubusercontent.com/u/119125167?v=4)](https://github.com/A909M "A909M (10 commits)")[![sertxudev](https://avatars.githubusercontent.com/u/22801379?v=4)](https://github.com/sertxudev "sertxudev (7 commits)")[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (6 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (6 commits)")[![jeffreyvanhees](https://avatars.githubusercontent.com/u/8754630?v=4)](https://github.com/jeffreyvanhees "jeffreyvanhees (6 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (6 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (4 commits)")[![jimirobaer](https://avatars.githubusercontent.com/u/8984769?v=4)](https://github.com/jimirobaer "jimirobaer (3 commits)")[![Nathan-Cowin](https://avatars.githubusercontent.com/u/91381012?v=4)](https://github.com/Nathan-Cowin "Nathan-Cowin (3 commits)")[![SandipGhimire](https://avatars.githubusercontent.com/u/200928662?v=4)](https://github.com/SandipGhimire "SandipGhimire (2 commits)")[![Seb33300](https://avatars.githubusercontent.com/u/915273?v=4)](https://github.com/Seb33300 "Seb33300 (2 commits)")[![ahme-d](https://avatars.githubusercontent.com/u/9767569?v=4)](https://github.com/ahme-d "ahme-d (2 commits)")[![stevethomas](https://avatars.githubusercontent.com/u/1127412?v=4)](https://github.com/stevethomas "stevethomas (2 commits)")[![vintagesucks](https://avatars.githubusercontent.com/u/13335308?v=4)](https://github.com/vintagesucks "vintagesucks (2 commits)")[![ycchuang99](https://avatars.githubusercontent.com/u/138915122?v=4)](https://github.com/ycchuang99 "ycchuang99 (2 commits)")[![albertStaalburger](https://avatars.githubusercontent.com/u/797741?v=4)](https://github.com/albertStaalburger "albertStaalburger (2 commits)")

---

Tags

laravelLaravel pdfMavorion

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mavorion-laravel-pdf-legacy/health.svg)

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

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k99.8M332](/packages/laravel-horizon)[spatie/laravel-health

Monitor the health of a Laravel application

88212.7M178](/packages/spatie-laravel-health)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

78727.1M203](/packages/laravel-mcp)[illuminate/queue

The Illuminate Queue package.

20433.0M1.7k](/packages/illuminate-queue)[illuminate/console

The Illuminate Console package.

13046.6M7.0k](/packages/illuminate-console)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.4M350](/packages/psalm-plugin-laravel)

PHPackages © 2026

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