PHPackages                             spiritix/php-chrome-html2pdf - 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. spiritix/php-chrome-html2pdf

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

spiritix/php-chrome-html2pdf
============================

A PHP library for converting HTML to PDF using Google Chrome

v1.8.1(1y ago)153472.0k↓19.4%33[2 issues](https://github.com/spiritix/php-chrome-html2pdf/issues)[2 PRs](https://github.com/spiritix/php-chrome-html2pdf/pulls)3MITPHPPHP ^8.1CI passing

Since Jan 8Pushed 1y ago4 watchersCompare

[ Source](https://github.com/spiritix/php-chrome-html2pdf)[ Packagist](https://packagist.org/packages/spiritix/php-chrome-html2pdf)[ RSS](/packages/spiritix-php-chrome-html2pdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (28)Used By (3)

PHP Chrome HTML to PDF
======================

[](#php-chrome-html-to-pdf)

A PHP library for converting HTML to PDF using Chrome/Chromium.

[![PHP Checks](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/php.yml/badge.svg)](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/php.yml)[![Node.js Checks](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/js.yml/badge.svg)](https://github.com/spiritix/php-chrome-html2pdf/actions/workflows/js.yml)[![Code Climate](https://camo.githubusercontent.com/3700592222c2dd9c443c7ab87c7b5908a1518dae6a3e18453610f0418bb4eb50/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73706972697469782f7068702d6368726f6d652d68746d6c327064662f6261646765732f6770612e737667)](https://codeclimate.com/github/spiritix/php-chrome-html2pdf)[![Total Downloads](https://camo.githubusercontent.com/c2edc304a5aed87ee6bac277333c2f18f9d7ec9a38641aadab1ff7850bbab5fe/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f7068702d6368726f6d652d68746d6c327064662f642f746f74616c2e737667)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)[![Latest Stable Version](https://camo.githubusercontent.com/dfbfb7739cfc5b35eb6808f601152bcb55e14a9de2396272db89f094ef911d74/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f7068702d6368726f6d652d68746d6c327064662f762f737461626c652e737667)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)[![Latest Unstable Version](https://camo.githubusercontent.com/5e46a97ba3de37ec3d6e5628cade9a1c681cc8907768f1412abd139dee079eca/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f7068702d6368726f6d652d68746d6c327064662f762f756e737461626c652e737667)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)[![License](https://camo.githubusercontent.com/c41e4a37faf991dbba4ff47a1241db21f9e47460a9dc1261e8013b54a6f594ea/68747470733a2f2f706f7365722e707567782e6f72672f73706972697469782f7068702d6368726f6d652d68746d6c327064662f6c6963656e73652e737667)](https://packagist.org/packages/spiritix/php-chrome-html2pdf)

*Contributors wanted! Have a look at the [open issues](https://github.com/spiritix/php-chrome-html2pdf/issues) and send me an email if you are interested in a quick introduction via Hangouts.*

How it works
------------

[](#how-it-works)

This library is based on [puppeteer](https://github.com/GoogleChrome/puppeteer), a headless Chrome Node API which is maintained by the Chrome DevTools team.

It provides a simple PHP wrapper around the Node API, focused on generating beautiful PDF files.

In contrast to other HTML to PDF converters like [wkhtmltopdf](https://wkhtmltopdf.org/), the corresponding [PHP wrapper](https://github.com/spiritix/html-to-pdf) or similar libraries, it is based on a current Chrome version instead of outdated and unmaintained WebKit builds. This library therefore fully supports CSS3, HTML5, SVGs, SPAs, and all the other fancy stuff people use these days.

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

[](#requirements)

- PHP 8.1+ with enabled program execution functions (proc\_open) and 'fopen wrappers'
- Node.js 18+ (for older Node.js versions use see [changelog](https://github.com/spiritix/php-chrome-html2pdf/blob/master/CHANGELOG.md))
- A few [OS specific dependencies](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)

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

[](#installation)

PHP Chrome HTML to PDF can be installed via [Composer](http://getcomposer.org) by requiring the `spiritix/php-chrome-html2pdf` package in your project's `composer.json`. Or simply run this command:

```
composer require spiritix/php-chrome-html2pdf
```

The required JS packages are installed automatically in the background.

Usage
-----

[](#usage)

Using this library is pretty straight forward. Decide for an input and an output handler, pass them to the converter, set some options if you like and depending on the output handler, proceed with the generated PDF file.

```
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\DownloadOutput;

$input = new UrlInput();
$input->setUrl('https://www.google.com');

$converter = new Converter($input, new DownloadOutput());

$converter->setOption('landscape', true);

$converter->setOptions([
    'printBackground' => true,
    'displayHeaderFooter' => true,
    'headerTemplate' => 'I am a header',
]);

$converter->setLaunchOptions([
      'ignoreHTTPSErrors' => true,
      'headless' => true,
      'executablePath' => '/usr/bin/google-chrome-stable',
      'args' => [
        '--no-sandbox',
        '--disable-web-security',
        '--font-render-hinting=none',
        '--proxy-server="direct://"',
        '--proxy-bypass-list=*',
        '--media-cache-size=0',
        '--disk-cache-size=0',
        '--disable-application-cache',
        '--disk-cache-dir=/dev/null',
        '--media-cache-dir=/dev/null'
      ]
   ]
);

$output = $converter->convert();
$output->download('google.pdf');
```

### Input handlers

[](#input-handlers)

The following input handlers are available:

- StringInput - Accepts the HTML content as a string
- UrlInput - Fetches the HTML content from an URL

### Output handlers

[](#output-handlers)

The following output handlers are available:

- StringOutput - Returns the binary PDF content as a string
- FileOutput - Stores the PDF file on the server's file system
- DownloadOutput - Forces the browser to download the PDF file
- EmbedOutput - Forces the browser to embed the PDF file

Options
-------

[](#options)

- `scale` &lt;\[number\]&gt; Scale of the webpage rendering. Defaults to `1`.
- `displayHeaderFooter` &lt;\[boolean\]&gt; Display header and footer. Defaults to `false`.
- `headerTemplate` &lt;\[string\]&gt; HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
    - `date` formatted print date
    - `title` document title
    - `url` document location
    - `pageNumber` current page number
    - `totalPages` total pages in the document
- `footerTemplate` &lt;\[string\]&gt; HTML template for the print footer. Should use the same format as the `headerTemplate`.
- `printBackground` &lt;\[boolean\]&gt; Print background graphics. Defaults to `false`.
- `landscape` &lt;\[boolean\]&gt; Paper orientation. Defaults to `false`.
- `pageRanges` &lt;\[string\]&gt; Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
- `format` &lt;\[string\]&gt; Paper format. If set, takes priority over `width` or `height` options. Defaults to 'Letter'.
- `width` &lt;\[string\]&gt; Paper width, accepts values labeled with units.
- `height` &lt;\[string\]&gt; Paper height, accepts values labeled with units.
- `margin` &lt;\[array\]&gt; Paper margins, defaults to none.
    - `top` &lt;\[string\]&gt; Top margin, accepts values labeled with units.
    - `right` &lt;\[string\]&gt; Right margin, accepts values labeled with units.
    - `bottom` &lt;\[string\]&gt; Bottom margin, accepts values labeled with units.
    - `left` &lt;\[string\]&gt; Left margin, accepts values labeled with units.
- `preferCSSPageSize` &lt;\[boolean\]&gt; Give any CSS @page size declared in the page priority over what is declared in width and height or format options. Defaults to `false`, which will scale the content to fit the paper size.
- `omitBackground` &lt;\[boolean\]&gt; Hides default white background and allows capturing screenshots with transparency. Defaults to `false`.
- `timeout` &lt;\[number\]&gt; Maximum time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout.
- `mediaType` &lt;?\[string\]&gt; Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables media emulation.
- `viewport` &lt;\[array\]&gt;
    - `width` &lt;\[number\]&gt; page width in pixels.
    - `height` &lt;\[number\]&gt; page height in pixels.
    - `deviceScaleFactor` &lt;\[number\]&gt; Specify device scale factor (can be thought of as dpr). Defaults to `1`.
    - `isMobile` &lt;\[boolean\]&gt; Whether the `meta viewport` tag is taken into account. Defaults to `false`.
    - `hasTouch`&lt;\[boolean\]&gt; Specifies if viewport supports touch events. Defaults to `false`
    - `isLandscape` &lt;\[boolean\]&gt; Specifies if viewport is in landscape mode. Defaults to `false`.
- `pageWaitFor` &lt;\[integer\]&gt; Timeout in milliseconds to wait for.
- `cookies`&lt;\[array\]&gt; Cookie objects to set.

> **NOTE** `headerTemplate` and `footerTemplate` markup have the following limitations:
>
> 1. Script tags inside templates are not evaluated.
> 2. Page styles are not visible inside templates.

> **NOTE** By default, this library generates a pdf with modified colors for printing. Use the `-webkit-print-color-adjust` property to force rendering of exact colors.

Troubleshooting
---------------

[](#troubleshooting)

- Make sure you've installed all [OS specific dependencies](https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix).
- Manually set the path to your Node.js executable using the `$converter->setNodePath()` method.
- Footer or header are not visible? See [here](https://github.com/spiritix/php-chrome-html2pdf/issues/66).

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

[](#contributing)

Contributions in any form are welcome. Please consider the following guidelines before submitting pull requests:

- **Coding standard** - It's mostly PSR.
- **Add tests!** - Your PR won't be accepted if it doesn't have tests.

License
-------

[](#license)

PHP Chrome HTML to PDF is free software distributed under the terms of the MIT license.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance41

Moderate activity, may be stable

Popularity53

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 70.5% 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 ~101 days

Recently: every ~124 days

Total

25

Last Release

621d ago

Major Versions

v0.1 → v1.02018-04-04

PHP version history (4 changes)v0.1PHP &gt;=7.0

v1.7PHP &gt;=8.0

v1.7.2PHP ^8.0

v1.7.6PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/8483fb2b022c51b2c219e3e562f6a1d4abbdf3c506e11872b04b1616c70f7fef?d=identicon)[spiritix](/maintainers/spiritix)

---

Top Contributors

[![spiritix](https://avatars.githubusercontent.com/u/2979494?v=4)](https://github.com/spiritix "spiritix (79 commits)")[![limenet](https://avatars.githubusercontent.com/u/474329?v=4)](https://github.com/limenet "limenet (14 commits)")[![fduarte42](https://avatars.githubusercontent.com/u/2005497?v=4)](https://github.com/fduarte42 "fduarte42 (5 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![Shotman](https://avatars.githubusercontent.com/u/6579166?v=4)](https://github.com/Shotman "Shotman (3 commits)")[![NiklasBr](https://avatars.githubusercontent.com/u/279826?v=4)](https://github.com/NiklasBr "NiklasBr (2 commits)")[![ZsgsDesign](https://avatars.githubusercontent.com/u/19504567?v=4)](https://github.com/ZsgsDesign "ZsgsDesign (1 commits)")[![dougblackjr](https://avatars.githubusercontent.com/u/6020323?v=4)](https://github.com/dougblackjr "dougblackjr (1 commits)")[![julius-fairmoney](https://avatars.githubusercontent.com/u/68551141?v=4)](https://github.com/julius-fairmoney "julius-fairmoney (1 commits)")[![peter-bartl](https://avatars.githubusercontent.com/u/71556602?v=4)](https://github.com/peter-bartl "peter-bartl (1 commits)")[![phillip-hopper](https://avatars.githubusercontent.com/u/5262964?v=4)](https://github.com/phillip-hopper "phillip-hopper (1 commits)")[![carestad](https://avatars.githubusercontent.com/u/65263?v=4)](https://github.com/carestad "carestad (1 commits)")

---

Tags

html2pdfhtmltopdfpdfpdf-converterphppuppeteerpuppeteer-pdfphppdfhtmlheadlesschromepuppeteerhtml2pdf

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spiritix-php-chrome-html2pdf/health.svg)

```
[![Health](https://phpackages.com/badges/spiritix-php-chrome-html2pdf/health.svg)](https://phpackages.com/packages/spiritix-php-chrome-html2pdf)
```

###  Alternatives

[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[chrome-php/chrome

Instrument headless chrome/chromium instances from PHP

2.6k4.5M64](/packages/chrome-php-chrome)[gotenberg/gotenberg-php

A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!

3685.2M19](/packages/gotenberg-gotenberg-php)[daandesmedt/phpheadlesschrome

A PHP wrapper for using Google Chrome Headless mode. Convert URL or HTML to a PDF / screenshot. Easy to use and OOP interfaced.

92233.1k](/packages/daandesmedt-phpheadlesschrome)[tesla-software/chrome2pdf

Convert HTML to Pdf using headless chrome.

308.1k](/packages/tesla-software-chrome2pdf)[its404/php-puppeteer

PHP Wrapper for Google Chrome Puppeteer

30303.1k1](/packages/its404-php-puppeteer)

PHPackages © 2026

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