Download the PHP package beganovich/snappdf without Composer

On this page you can find all versions of the php package beganovich/snappdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package snappdf

snappdf logo

Github Actions Status

snappdf

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

Usage

Here's quick example, how it works:

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

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

Laravel usage with blade templates

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

This is example for Nginx configuration (server block) (thanks @cdahinten):

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

Note: setChromiumPath has highest priority. Second one is environment variable & 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:

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

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.

Command-line usage:

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

In case you want to convert HTML:

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

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.

Requirements

Installation

Composer is recommended way of installing library:

Downloading local Chromium

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

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 & 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 & stability is your top priority, please install Google Chrome stable version & point package to use that.

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

Make sure your system has installed all required dependencies. Thanks Puppeteer

Debian (e.g. Ubuntu)
CentOS After installing dependencies you need to update nss library using this command
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

In case you need much more complex software to perform operations with headless browser go for Spatie's Browsershot. It's fantastic package. Purpose of snappdf is to be really minimal & only focus on making PDFs.

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

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 & then action the printing.

TLDR; If you set delay loading to 10 seconds & 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

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.

Credits

Licence

The MIT License (MIT).


All versions of snappdf with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-zip Version *
symfony/process Version ^7.0
symfony/console Version ^7.0
symfony/filesystem Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package beganovich/snappdf contains the following files

Loading the files please wait ....