PHPackages                             marucat/php-puppeteer - 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. marucat/php-puppeteer

ActivePhp-wrapper[PDF &amp; Document Generation](/categories/documents)

marucat/php-puppeteer
=====================

PHP Wrapper for Google Chrome Puppeteer

0.1.1(8y ago)021MITPHPPHP &gt;=5.4.0

Since Jan 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/marucat/php-puppeteer)[ Packagist](https://packagist.org/packages/marucat/php-puppeteer)[ Docs](http://github.com/its404/php-puppeteer)[ RSS](/packages/marucat-php-puppeteer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (3)Used By (0)

PHP Puppeteer
=============

[](#php-puppeteer)

This project provides the ability to generate PDF/PNG with [Puppeteer](https://github.com/GoogleChrome/puppeteer) in PHP

Dependencies
============

[](#dependencies)

The library is running based on [Nodejs](https://nodejs.org/en/)(7.6 above) and [Puppeteer](https://github.com/GoogleChrome/puppeteer)It is tested under NodeJS 8.

Installation on CentOS 7:

```
sudo curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum install -y nodejs pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc
sudo npm install --global --unsafe-perm puppeteer
sudo chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium

```

Installation on Ubuntu 16.04:

```
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 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 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
sudo npm install --global --unsafe-perm puppeteer
sudo chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium

```

Installation
============

[](#installation)

Install `marucat/php-puppeteer` using Composer.

```
composer require marucat/php-puppeteer

```

Usage
=====

[](#usage)

Parameters
----------

[](#parameters)

The library has set some default parameter values to support basic features, you can set the customized parameters to override the default ones, it supports all parameters of [Puppeteer API](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md)

**Sample parameter array:**

```
$config  = [
    'html' => "Hello World",
	'pdf' => [
		'path' => '/tmp/test.pdf',
		'margin' => [
			'top' => '10mm',
			'right' => '10mm',
			'bottom' => '10mm',
			'left' => '10mm',
		]
	]
];

```

> **Note:**

1. If both `$config['pdf']['html']` and $config\['pdf'\]\['url'\] are set, `html` will be picked up.
2. If `$config['pdf']['path']` is not set, will return pdf data

Import
------

[](#import)

You need to import this namespace at the top of your PHP class

```
use Marucat\PhpPuppeteer\Browser;

```

**PDF by URL**

You can generate PDF by URL through `pdf` function:

```
public function actionTest1()
{
	$config = [
		"url" => "https://www.highcharts.com/demo/line-basic",
	];
	$browser = new Browser();
	$browser->isDebug = true;
	$content = $browser->pdf($config);

	header("Content-type:application/pdf");
	echo $content;
}

```

You can set any parameter in `$config` to override the default values

**PDF by HTML**

You can generate PDF by html code through `pdf` function:

```
public function actionTest2()
{
	$config = [
		"html" => "Hello Wolrd"
	];
	$browser = new Browser();
	$content = $browser->pdf($config);

	header("Content-type:application/pdf");
	echo $content;
}

```

> **Debug** The class `Browser` has one parameter `$isDebug`, it would be debug mode if it's `true`, detailed error messages would be returned from `pdf` function if an error happened during Puppeteer running.

**PDF to specific path**

You can generate PDF to a specific path by setting `$config['pdf']['path']`

```
public function actionTest3()
{
	$config = [
		"html" => "Hello Wolrd",
		'pdf' => [
			'path' => '/tmp/test.pdf',
		]
	];
	$browser = new Browser();
	$browser->isDebug = true;
	$result = $browser->pdf($params);

	if (isset($result['returnVal'])&& $result['returnVal'] == 0) {
		echo "PDF generated successfully";
	} else {
		echo "Failed to generate PDF";
		var_dump($result['output']);
	}
}

```

**Start a new page on PDF**

You can add following html code in the html where you'd like to start a new page for PDF.

```

```

More Examples?
==============

[](#more-examples)

You can find more examples from [here](https://github.com/marucat/php-puppeteer/tree/master/examples)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~2 days

Total

2

Last Release

3048d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0dc226d605cb0cc97dedf24e215c51cddcf5d95f01235b1eab37edf3c2f1511f?d=identicon)[marucat](/maintainers/marucat)

---

Top Contributors

[![its404](https://avatars.githubusercontent.com/u/35132886?v=4)](https://github.com/its404 "its404 (8 commits)")[![marucat](https://avatars.githubusercontent.com/u/11462162?v=4)](https://github.com/marucat "marucat (2 commits)")

---

Tags

phppdfscreenshotpuppeteer

### Embed Badge

![Health badge](/badges/marucat-php-puppeteer/health.svg)

```
[![Health](https://phpackages.com/badges/marucat-php-puppeteer/health.svg)](https://phpackages.com/packages/marucat-php-puppeteer)
```

###  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)[its404/php-puppeteer

PHP Wrapper for Google Chrome Puppeteer

30303.1k1](/packages/its404-php-puppeteer)[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)[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)
