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(4d ago)219364.2k↓50.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 4d ago4 watchersCompare

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

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

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

[![Github Actions Status](https://github.com/beganovich/snappdf/actions/workflows/phpunit.yml/badge.svg)](https://github.com/beganovich/snappdf/actions/workflows/phpunit.yml/badge.svg)

snappdf
=======

[](#snappdf)

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

- [snappdf](#snappdf)
    - [Usage](#usage)
        - [Command-line usage:](#command-line-usage)
    - [Speed](#speed)
    - [Requirements](#requirements)
    - [Installation](#installation)
        - [Downloading local Chromium](#downloading-local-chromium)
        - [Skip the Chromium download](#skip-the-chromium-download)
        - [Headless Chrome doesn't launch on UNIX](#headless-chrome-doesnt-launch-on-unix)
        - [Comparison to Browsershot](#comparison-to-browsershot)
        - [Delay loading](#delay-loading)
        - [Temporary files](#temporary-files)
    - [Credits](#credits)
    - [Licence](#licence)

Usage
-----

[](#usage)

Here's quick example, how it works:

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

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

In case you want to convert web page into the PDF, you can use `setUrl()` instead of `setHtml()`:

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

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

.. if you need specific version of Chrome, or don't want to use locally downloaded Chromium, make use of `setChromiumPath` method.

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

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

Laravel usage with blade templates

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

$fields = [...];

// Render method returns HTML string (template compile)
$html = view('pdf.warranty', compact('fields'))->render();

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

If none of previously listed option fits your needs, you can also set path to executable Chromium with environment variable.

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

This is example for Nginx configuration (server block) (thanks [@cdahinten](https://github.com/beganovich/snappdf/issues/15#issuecomment-776135341)):

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

```

If you need to generate PDF only, without saving it, make use of `generate()`:

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

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

file_put_contents('my.pdf', $pdf); // for local storage

Storage::disk('s3')->put('my.pdf', $pdf); // for remote storage
```

Note: `setChromiumPath` has highest priority. Second one is environment variable &amp; third local download.

While the default arguments should work in most use cases, but it is possible to specify which arguments to use:

Using the `addChromiumArguments` Method:

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

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setChromiumPath('/path/to/your/chrome')
    ->addChromiumArguments('--single-process --tls1')
    ->generate();
```

If you want to remove single argument, you can make use of `clearChromiumArgument`.

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

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

In the event you want to override the default arguments, you can use the the `SNAPPDF_EXECUTABLE_ARGUMENTS` environmental variable.

NOTE: The `--print-to-pdf` argument is always added, and the `--virtual-time-budget` argument is added whenever the `waitBeforePrinting` method is called.

To clear all arguments you can use the `clearChromiumArguments` method.

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

// $snappdf->getChromiumArguments() = [ '--headless', '--disable-gpu', ... ]

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

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

#### Command-line usage:

[](#command-line-usage)

If you want to use snappdf as command-line tool, make use of "convert" command:

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

In case you want to convert HTML:

```
./vendor/bin/snappdf convert --html "Hello world!" /path/to/save.pdf
```

You can also specify custom binary location (if you don't use locally downloaded Chromium revision):

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

Speed
-----

[](#speed)

Main benefit and reason why this library exists is the speed of generating PDFs. It communicates directly with browser itself and it takes less than .5s to generate PDFs (with cold start). This was tested on mid-range laptop with i5-5300U and average SSD.

```
➜  snappdf git:(master) ./vendor/bin/phpunit --testdox --filter=testGeneratingPdfWorks
PHPUnit 9.5.0 by Sebastian Bergmann and contributors.

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

Time: 00:00.199, Memory: 6.00 MB

OK (1 test, 1 assertion)
➜  snappdf git:(master) ./vendor/bin/phpunit --testdox --filter=testGeneratingPdfWorks
PHPUnit 9.5.0 by Sebastian Bergmann and contributors.

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

Time: 00:00.171, Memory: 6.00 MB

OK (1 test, 1 assertion)
```

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

[](#requirements)

- PHP 8

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

[](#installation)

Composer is recommended way of installing library:

```
composer require beganovich/snappdf
```

### Downloading local Chromium

[](#downloading-local-chromium)

snappdf can download &amp; use local revision of Chromium. To achieve that, you can use:

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

You can find local downloads/revisions in `%projectRoot%/vendor/beganovich/snappdf/versions`.

Local revision will be used **only** when you don't provide path using `setChromiumPath()`.

**Note:** snappdf will download &amp; use latest build of Chromium. Since Chromium itself doesn't have stable or unstable release, browser itself can be buggy or possibly broken. We don't take any responsibility for that. **If security &amp; stability is your top priority, please install Google Chrome stable version &amp; point package to use that.**

### Skip the Chromium download

[](#skip-the-chromium-download)

If you need to dynamically skip the download, make use of `SNAPPDF_SKIP_DOWNLOAD` environment variable.

### Headless Chrome doesn't launch on UNIX

[](#headless-chrome-doesnt-launch-on-unix)

Make sure your system has installed all required dependencies. Thanks [Puppeteer](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 need to install ‘libgbm-dev’ and ‘libxshmfence-dev’ also. This is 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 you need to update nss library using this command

```
yum update nss -y

```

 Check out 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

### Comparison to Browsershot

[](#comparison-to-browsershot)

In case you need much more complex software to perform operations with headless browser go for [Spatie's Browsershot](https://github.com/spatie/browsershot). It's fantastic package. Purpose of snappdf is to be really minimal &amp; only focus on making PDFs.

Also, snappdf doesn't need Node installed to operate.

### Delay loading

[](#delay-loading)

You can use `waitBeforePrinting()` to set maximum delay before running the print. Use case for this would be if you need to make an Ajax call or wait for library (e.g. charts) to load before printing.

**Note:**Values provided are in milliseconds. One really important note is: If you delay load by 10 seconds (10000) it won't delay PDF rendering itself by 10s, but it will give time for libraries or Ajax calls to finish &amp; then action the printing.

TLDR; If you set delay loading to 10 seconds &amp; Ajax call takes 2 seconds to complete, PDF rendering will start immediately after Ajax call is completed (after 2 seconds), and it won't wait 10 seconds.

### Temporary files

[](#temporary-files)

Starting with version 3, snappdf will automatically get rid of temporary files. If you still want to keep them, you can do it using `setKeepTemporaryFiles` method.

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

$pdf = $snappdf
    ->setUrl('https://github.com')
    ->setChromiumPath('/path/to/your/chrome')
    ->setKeepTemporaryFiles(true)
    ->generate();

file_put_contents('my.pdf', $pdf);
```

Credits
-------

[](#credits)

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

Licence
-------

[](#licence)

The MIT License (MIT).

###  Health Score

67

—

FairBetter than 99% of packages

Maintenance98

Actively maintained with recent releases

Popularity53

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

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

4d 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 (110 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

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[drupal/core

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

21866.0M1.7k](/packages/drupal-core)[drupal/core-recommended

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

6942.5M421](/packages/drupal-core-recommended)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M577](/packages/shopware-core)[jolicode/castor

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

54743.1k4](/packages/jolicode-castor)

PHPackages © 2026

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