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

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

codestudios/php-chrome-html2pdf
===============================

A PHP library for converting HTML to PDF using Google Chrome

1.4.2(5y ago)1228MITPHPPHP &gt;=7.0

Since Jan 8Pushed 5y agoCompare

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

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

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

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

A PHP library for converting HTML to PDF using Google Chrome.

[![Build Status](https://camo.githubusercontent.com/357c2144d82c3a9e9cdd0c5a1b830a942394f21aa818175aa52a382584ebefb8/68747470733a2f2f7472617669732d63692e6f72672f73706972697469782f7068702d6368726f6d652d68746d6c327064662e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/spiritix/php-chrome-html2pdf)[![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)

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 7.0+ with enabled program execution functions (proc\_open) and 'fopen wrappers'
- Node.js 6.4+
- A few [OS specific dependencies](https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md)

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,
    'headerTemplate' => 'I am a header',
]);

$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.
- `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/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md).
- Manually set the path to your Node.js executable using the `$converter->setNodePath()` method.

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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 78.8% 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 ~79 days

Recently: every ~116 days

Total

12

Last Release

2174d ago

Major Versions

v0.1 → v1.02018-04-04

### Community

Maintainers

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

---

Top Contributors

[![spiritix](https://avatars.githubusercontent.com/u/2979494?v=4)](https://github.com/spiritix "spiritix (26 commits)")[![fduarte42](https://avatars.githubusercontent.com/u/2005497?v=4)](https://github.com/fduarte42 "fduarte42 (5 commits)")[![Codestudios](https://avatars.githubusercontent.com/u/11913923?v=4)](https://github.com/Codestudios "Codestudios (2 commits)")

---

Tags

phppdfhtmlheadlesschromepuppeteerhtml2pdf

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spiritix/php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome

153472.0k3](/packages/spiritix-php-chrome-html2pdf)[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)

PHPackages © 2026

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