PHPackages                             fyrts/chrome-devtools-pdf - 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. fyrts/chrome-devtools-pdf

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

fyrts/chrome-devtools-pdf
=========================

A simple PHP library for generating PDF files using the Chrome DevTools Protocol

1.2.0(3y ago)4279MITPHP

Since Jul 9Pushed 3y agoCompare

[ Source](https://github.com/Fyrts/chrome-devtools-pdf)[ Packagist](https://packagist.org/packages/fyrts/chrome-devtools-pdf)[ RSS](/packages/fyrts-chrome-devtools-pdf/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

ChromeDevToolsPdf
=================

[](#chromedevtoolspdf)

ChromeDevToolsPdf provides a wrapper around [fyrts/chrome-devtools-protocol](https://github.com/fyrts/chrome-devtools-protocol) for fast and predictable generation of PDF files using the Chrome DevTools Protocol.

Setup
-----

[](#setup)

Start off by installing a recent version of Chrome/Chromium, then install the package through [composer](http://getcomposer.org):

```
composer require fyrts/chrome-devtools-pdf

```

You can choose to manage the Chrome process yourself (preferably using a process manager like [Supervisord](http://supervisord.org)), or have the library fire up a process on request.

To share a single process, start Chrome with the `remote-debugging-port` flag and use the `connect()` method:

```
$instance = ChromeDevToolsPdf\Instance::connect(9222);
```

To launch Chrome on demand, use the `launch()` method, providing the executable path if needed:

```
$instance = ChromeDevToolsPdf\Instance::launch('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome');
```

Usage
-----

[](#usage)

PDF files can be generated from either publicly accessible URLs, or raw HTML source code.

```
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadUrl('https://www.google.com');
$pdf->saveFile(__DIR__ . '/filename.pdf');
$instance->close();
```

```
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadHtml('Example');
$pdf->saveFile(__DIR__ . '/filename.pdf');
$instance->close();
```

To receive raw data instead of directly saving a file, use the `generate()` method instead:

```
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadUrl('https://www.google.com');
Storage::put($__DIR__ . '/filename.pdf', $pdf->generate());
$instance->close();
```

Change page layout settings by calling setters on the PDF object:

```
$instance = ChromeDevToolsPdf\Instance::launch();
$pdf = $instance->loadUrl('https://www.google.com');
$pdf->setLandscape(true)->setMarginLeft(3);
$pdf->setDisplayHeaderFooter(true)->setHeaderTemplate('Title: ');
$pdf->saveFile(__DIR__ . '/filename.pdf');
$instance->close();
```

Available options are as follows:

- `setLandscape(true|false)` – Paper orientation. Defaults to false.
- `setDisplayHeaderFooter(true|false)` – Display header and footer. Defaults to false.
- `setPrintBackground(true|false)` – Print background graphics. Defaults to false.
- `setScale(int|float)` – Scale of the webpage rendering. Defaults to 1.
- `setPaperWidth(int|float)` and `setPaperHeight(int|float)` – Paper width or height in inches. Defaults to 8.5 and 11 inches respectively.
- `setMarginTop(int|float)`, `setMarginBottom(int|float)`, `setMarginLeft(int|float)` and `setMarginRight(int|float)` – Top, bottom, left or right margin in inches. Defaults to 1cm (~0.4 inches).
- `setPageRanges(string)` – Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
- `setIgnoreInvalidPageRanges(true|false)` – Whether to silently ignore invalid but successfully parsed page ranges, such as '3-2'. Defaults to false.
- `setHeaderTemplate(string)` – HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them (for example,  would generate span containing the title):
    - date: formatted print date
    - title: document title
    - url: document location
    - pageNumber: current page number
    - totalPages: total pages in the document
- `setFooterTemplate(string)` – HTML template for the print footer. Should use the same format as the headerTemplate.
- `setPreferCSSPageSize(true|false)` – Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
- `setPaperSize(array)` – Array containing paper width and height in inches. Defaults to 8.5 and 11 inches respectively. The following constants are available as presets:
    - PaperSize::A0, PaperSize::A1, PaperSize::A2, PaperSize::A3, PaperSize::A4, PaperSize::A5, PaperSize::A6, PaperSize::A7 and PaperSize::A8
    - PaperSize::JUNIOR\_LEGAL
    - PaperSize::GOVERNMENT\_LETTER
    - PaperSize::LETTER
    - PaperSize::LEGAL
    - PaperSize::TABLOID
    - PaperSize::LEDGER

The library can be implemented asynchronously. This can be useful when printing multiple pages. When doing so, use the `await()` method to prevent the script from terminating prematurely.

```
$instance = ChromeDevToolsPdf\Instance::launch();

$pdf1 = $instance->loadUrl('https://www.google.com');
$pdf1->saveFileAsync(__DIR__ . '/filename-1.pdf');

$pdf2 = $instance->loadUrl('https://www.github.com');
$pdf2->saveFileAsync(__DIR__ . '/filename-2.pdf');

$pdf1->await();
$pdf2->await();

$instance->close();
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~419 days

Total

4

Last Release

1246d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2fe7a44c5e07cf8dd0eed2941b88dcab03342fb149ede5347b3467bc17691d4e?d=identicon)[Fyrts](/maintainers/Fyrts)

---

Top Contributors

[![fyrts](https://avatars.githubusercontent.com/u/5918336?v=4)](https://github.com/fyrts "fyrts (6 commits)")

---

Tags

phppdfDevtoolschromechromium

### Embed Badge

![Health badge](/badges/fyrts-chrome-devtools-pdf/health.svg)

```
[![Health](https://phpackages.com/badges/fyrts-chrome-devtools-pdf/health.svg)](https://phpackages.com/packages/fyrts-chrome-devtools-pdf)
```

###  Alternatives

[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)[spiritix/php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome

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

PHP library allowing PDF generation from an url or a html page. Wrapper for Kozea/WeasyPrint.

761.1M7](/packages/pontedilana-php-weasyprint)[kartik-v/mpdf

A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support. This is a fork of the official mPDF library.

39328.4k1](/packages/kartik-v-mpdf)

PHPackages © 2026

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