PHPackages                             beganovich/snappdf - 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. beganovich/snappdf

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

beganovich/snappdf
==================

Convert webpages or HTML into the PDF file using Chromium or Google Chrome.

v6.1.0(1mo ago)218372.0k↓52.7%17[11 issues](https://github.com/beganovich/snappdf/issues)[1 PRs](https://github.com/beganovich/snappdf/pulls)1MITPHPPHP &gt;=8.2CI passing

Since Dec 21Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/beganovich/snappdf)[ Packagist](https://packagist.org/packages/beganovich/snappdf)[ RSS](/packages/beganovich-snappdf/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (10)Versions (29)Used By (1)

 [![snappdf](https://raw.githubusercontent.com/beganovich/snappdf/master/cover.png)](https://raw.githubusercontent.com/beganovich/snappdf/master/cover.png)

 [![Packagist Version](https://camo.githubusercontent.com/b6166b43066b3423b9b762cd38965ceda53f752e4d0d2038071b75aad8255b33/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626567616e6f766963682f736e61707064663f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beganovich/snappdf) [![Total Downloads](https://camo.githubusercontent.com/35ab4fde4ecc0522fdedac0d83fd4be0a038a0653e9b52f880794f66732f20b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626567616e6f766963682f736e61707064663f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beganovich/snappdf) [![CI Status](https://github.com/beganovich/snappdf/actions/workflows/phpunit.yml/badge.svg?branch=master&style=flat-square)](https://github.com/beganovich/snappdf/actions/workflows/phpunit.yml) [![PHP Version](https://camo.githubusercontent.com/441f0e8a7ca26d23383a9e2520173498e76c0703ca2e4c85b5555c61e66ecc9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f626567616e6f766963682f736e61707064663f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beganovich/snappdf) [![License](https://camo.githubusercontent.com/40e395f7de568dc8ab28572cb14888d24e52885099674a380b1d01fa5d90c9b9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f626567616e6f766963682f736e61707064663f7374796c653d666c61742d737175617265)](https://github.com/beganovich/snappdf/blob/master/LICENSE)

snappdf
=======

[](#snappdf)

A simple library that lets you convert webpages or HTML into PDF files using Chromium-powered browsers.

Features
--------

[](#features)

- **Fast** — Generates PDFs in under 0.5 seconds with cold start
- **No Node.js required** — Communicates directly with the browser
- **Minimal API** — Focused solely on PDF generation
- **Local Chromium** — Downloads and manages its own Chromium revision
- **Flexible configuration** — Custom binary path, arguments, and environment variables
- **Smart timing** — Virtual time budget for waiting on async content

Requirements
------------

[](#requirements)

- PHP ^8.2

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

[](#installation)

```
composer require beganovich/snappdf
```

Quick Start
-----------

[](#quick-start)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setHtml('Hello world!')
    ->save('/path/to/your/file.pdf');
```

Usage
-----

[](#usage)

### From HTML

[](#from-html)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setHtml('Hello world!')
    ->save('/path/to/your/file.pdf');
```

### From URL

[](#from-url)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->save('/path/to/your/file.pdf');
```

### Custom Chromium Path

[](#custom-chromium-path)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setChromiumPath('/path/to/your/chrome')
    ->save('/path/to/your/file.pdf');
```

### Laravel with Blade

[](#laravel-with-blade)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$html = view('pdf.warranty', $fields)->render();

$pdf = $snappdf
    ->setHtml($html)
    ->save('/path/to/your/file.pdf');
```

### Symfony Filesystem

[](#symfony-filesystem)

```
use Symfony\Component\Filesystem\Filesystem;

$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setHtml('Hello world!')
    ->generate();

$filesystem = new Filesystem();
$filesystem->dumpFile('/path/to/your/file.pdf', $pdf);
```

### Environment Variable

[](#environment-variable)

```
SNAPPDF_EXECUTABLE_PATH=/path/to/your/chrome
```

Nginx example:

```
fastcgi_param SNAPPDF_EXECUTABLE_PATH '/usr/bin/chromium';
fastcgi_param SNAPPDF_SKIP_DOWNLOAD true;

```

### Generate Without Saving

[](#generate-without-saving)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->generate();

file_put_contents('my.pdf', $pdf);
Storage::disk('s3')->put('my.pdf', $pdf);
```

### Stream to Browser

[](#stream-to-browser)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setHtml('Hello world!')
    ->generate();

header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="document.pdf"');
echo $pdf;
```

**Priority:** `setChromiumPath()` takes precedence, then `SNAPPDF_EXECUTABLE_PATH`, then local Chromium download.

Configuration
-------------

[](#configuration)

### Chromium Arguments

[](#chromium-arguments)

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$snappdf
    ->setUrl('https://github.com')
    ->addChromiumArguments('--single-process --tls1')
    ->generate();
```

Remove a single argument:

```
$snappdf->getChromiumArguments();
// ['--headless', '--disable-gpu', '--disable-translations']

$snappdf->clearChromiumArgument('--headless');
// ['--disable-gpu', '--disable-translations']
```

Override all default arguments with the `SNAPPDF_EXECUTABLE_ARGUMENTS` environment variable.

> **Note:** `--print-to-pdf` is always added. `--virtual-time-budget` is added when `waitBeforePrinting()` is called.

Clear all arguments:

```
$snappdf->setChromiumPath('/path/to/your/chrome')
    ->clearChromiumArguments();

// $snappdf->getChromiumArguments() = []
```

CLI Usage
---------

[](#cli-usage)

```
# Convert a URL
./vendor/bin/snappdf convert --url https://github.com /path/to/save.pdf

# Convert raw HTML
./vendor/bin/snappdf convert --html 'Hello world!' /path/to/save.pdf

# With custom binary
./vendor/bin/snappdf convert --url https://github.com --binary /usr/bin/google-chrome /path/to/save.pdf
```

Speed
-----

[](#speed)

snappdf communicates directly with the browser, generating PDFs in under 0.5 seconds with cold start on mid-range hardware (i5-5300U, SSD).

```
./vendor/bin/phpunit --testdox --filter=testGeneratingPdfWorks
PHPUnit 11.4.0 by Sebastian Bergmann and contributors.

Snappdf (Test\Snappdf\Snappdf)
 ✔ Generating pdf works

Time: 00:00.171, Memory: 6.00 MB

```

Chromium Management
-------------------

[](#chromium-management)

### Local Download

[](#local-download)

```
./vendor/bin/snappdf download
```

Downloads are stored in `vendor/beganovich/snappdf/versions`. The local revision is used only when no path is provided via `setChromiumPath()`.

> **Note:** snappdf downloads the latest Chromium build. Since Chromium has no stable or unstable releases, the browser may occasionally be buggy. For production environments, install Google Chrome stable and point the package to it.

### Skip Download

[](#skip-download)

Set the `SNAPPDF_SKIP_DOWNLOAD` environment variable to skip downloading Chromium.

### Troubleshooting

[](#troubleshooting)

If Chrome doesn't launch on UNIX, ensure the required system dependencies are installed. See [Puppeteer's troubleshooting guide](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix).

Debian (e.g. Ubuntu)```
ca-certificates
fonts-liberation
libappindicator3-1
libasound2
libatk-bridge2.0-0
libatk1.0-0
libc6
libcairo2
libcups2
libdbus-1-3
libexpat1
libfontconfig1
libgbm1
libgcc1
libglib2.0-0
libgtk-3-0
libnspr4
libnss3
libpango-1.0-0
libpangocairo-1.0-0
libstdc++6
libx11-6
libx11-xcb1
libxcb1
libxcomposite1
libxcursor1
libxdamage1
libxext6
libxfixes3
libxi6
libxrandr2
libxrender1
libxss1
libxtst6
lsb-release
wget
xdg-utils

```

Note: You might also need `libgbm-dev` and `libxshmfence-dev` (reported for Ubuntu 20.04).

CentOS```
alsa-lib.x86_64
atk.x86_64
cups-libs.x86_64
gtk3.x86_64
ipa-gothic-fonts
libXcomposite.x86_64
libXcursor.x86_64
libXdamage.x86_64
libXext.x86_64
libXi.x86_64
libXrandr.x86_64
libXScrnSaver.x86_64
libXtst.x86_64
pango.x86_64
xorg-x11-fonts-100dpi
xorg-x11-fonts-75dpi
xorg-x11-fonts-cyrillic
xorg-x11-fonts-misc
xorg-x11-fonts-Type1
xorg-x11-utils

```

After installing dependencies, update nss:

```
yum update nss -y

```

Related discussions- [\#290](https://github.com/puppeteer/puppeteer/issues/290) — Debian troubleshooting
- [\#391](https://github.com/puppeteer/puppeteer/issues/391) — CentOS troubleshooting
- [\#379](https://github.com/puppeteer/puppeteer/issues/379) — Alpine troubleshooting

Smart Delay
-----------

[](#smart-delay)

Use `waitBeforePrinting()` to set a maximum delay (in milliseconds) before printing. This is useful for waiting on AJAX calls or chart libraries to finish loading.

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->waitBeforePrinting(10000)
    ->generate();
```

If your AJAX call completes in 2 seconds, rendering starts immediately — it won't wait the full 10 seconds.

Temporary Files
---------------

[](#temporary-files)

Since version 3, snappdf cleans up temporary files automatically. To keep them:

```
$snappdf = new \Beganovich\Snappdf\Snappdf();

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setKeepTemporaryFiles(true)
    ->generate();
```

Comparison to Browsershot
-------------------------

[](#comparison-to-browsershot)

For more complex headless browser operations, use [Spatie's Browsershot](https://github.com/spatie/browsershot). snappdf is intentionally minimal — it only does PDFs and doesn't require Node.js.

Testing
-------

[](#testing)

```
composer tests
```

Credits
-------

[](#credits)

- [David Bomba](https://github.com/turbo124)
- [Benjamin Beganović](https://github.com/beganovich)
- [All contributors](https://github.com/beganovich/snappdf/contributors)

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for more information.

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance91

Actively maintained with recent releases

Popularity53

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 90.4% 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 ~80 days

Recently: every ~208 days

Total

26

Last Release

49d ago

Major Versions

1.x-dev → v2.2.02022-06-29

v2.2.0 → v3.02022-09-14

v3.1.0 → v4.0.02023-04-22

v4.0.3 → 5.x-dev2024-03-20

v5.0.1 → v6.0.02026-01-03

PHP version history (6 changes)v1.0.0PHP ^7.3|^7.4|^8.0

v1.9.0PHP ^7.3|^7.4|^8.0|^8.1

v2.0.0PHP ^8.0

v2.2.0PHP ^8.0|^8.1

v4.0.0PHP ^8.1|^8.2

5.x-devPHP &gt;=8.2

### Community

Maintainers

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

---

Top Contributors

[![beganovich](https://avatars.githubusercontent.com/u/13711415?v=4)](https://github.com/beganovich "beganovich (113 commits)")[![d13r](https://avatars.githubusercontent.com/u/236616?v=4)](https://github.com/d13r "d13r (3 commits)")[![turbo124](https://avatars.githubusercontent.com/u/5827962?v=4)](https://github.com/turbo124 "turbo124 (3 commits)")[![MikeHopley](https://avatars.githubusercontent.com/u/856145?v=4)](https://github.com/MikeHopley "MikeHopley (1 commits)")[![phpdave11](https://avatars.githubusercontent.com/u/9421180?v=4)](https://github.com/phpdave11 "phpdave11 (1 commits)")[![sniper7kills](https://avatars.githubusercontent.com/u/5902574?v=4)](https://github.com/sniper7kills "sniper7kills (1 commits)")[![zachariah-mithani](https://avatars.githubusercontent.com/u/118302440?v=4)](https://github.com/zachariah-mithani "zachariah-mithani (1 commits)")[![egyjs](https://avatars.githubusercontent.com/u/12745270?v=4)](https://github.com/egyjs "egyjs (1 commits)")[![kallesprd](https://avatars.githubusercontent.com/u/100536300?v=4)](https://github.com/kallesprd "kallesprd (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/beganovich-snappdf/health.svg)

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

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k199.6M3.4k](/packages/composer-composer)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k39.6k](/packages/matomo-matomo)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19467.3M1.9k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6943.5M449](/packages/drupal-core-recommended)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.8M674](/packages/shopware-core)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

55344.7k5](/packages/jolicode-castor)

PHPackages © 2026

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