PHPackages                             dawood/phpchromepdf - 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. [CLI &amp; Console](/categories/cli)
4. /
5. dawood/phpchromepdf

ActiveLibrary[CLI &amp; Console](/categories/cli)

dawood/phpchromepdf
===================

A slim PHP wrapper around google-chrome to convert url to pdf or to take screenshots , easy to use and clean OOP interface

v1.3(8y ago)14980.5k↓19.2%21[1 issues](https://github.com/daudmalik06/PhpChromeToPdf/issues)MITPHP

Since Jul 8Pushed 2y ago12 watchersCompare

[ Source](https://github.com/daudmalik06/PhpChromeToPdf)[ Packagist](https://packagist.org/packages/dawood/phpchromepdf)[ RSS](/packages/dawood-phpchromepdf/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

PHP ChromeToPdf
===============

[](#php-chrometopdf)

[![Latest Stable Version](https://camo.githubusercontent.com/8fb74c1ade6146096a4598726fa9e781e9082768427418ff1aa8f25bc1edb3df/68747470733a2f2f706f7365722e707567782e6f72672f6461776f6f642f7068706368726f6d657064662f762f737461626c652e737667)](https://packagist.org/packages/dawood/phpchromepdf)[![Total Downloads](https://camo.githubusercontent.com/d31983c6798443a8d57776cd5d681ba8c938e4c6578169b518cc08650ff0f62c/68747470733a2f2f706f7365722e707567782e6f72672f6461776f6f642f7068706368726f6d657064662f646f776e6c6f616473)](https://packagist.org/packages/dawood/phpchromepdf)[![License](https://camo.githubusercontent.com/c15f4ef0179c5811bcfe73c6d4d87512cdcbcfaaae8e0b62db5c8dc4cc0ae294/68747470733a2f2f706f7365722e707567782e6f72672f6461776f6f642f7068706368726f6d657064662f6c6963656e73652e737667)](https://packagist.org/packages/dawood/phpchromepdf)

PHP ChromeToPdf provides a simple and clean interface to ease PDF and image creation with [Google Chrome](https://www.google.com/chrome/). **The `Google Chrome`must be installed and working on your system.** See the section below for details.

History
-------

[](#history)

Every time i had convert url to pdf or to take screenshot of some url i had to install several libraries , i know there are very good libraries available like phantomJs,wkhtmltopdf and some others... but there are always rendering issue
like some supports **bootstrap** ,some not some time **html5 problem** etc..
and this was all annoying so i decided to make this little wrapper around chrome
by using chrome results i achieved following results.

- **No more css issues (bootstrap,css3 )**
- **No more html5 issues**
- **No more need to use xvfb**

**in-fact painless conversion**

Installation ( Laravel )
------------------------

[](#installation--laravel-)

This package supports Laravel. Install it in a Laravel application as follows:

```
composer require dawood/phpchromepdf

```

done.

Installation ( Simple PHP App )
-------------------------------

[](#installation--simple-php-app-)

Install the package through [composer](http://getcomposer.org):

```
composer require dawood/phpchromepdf

```

Make sure, that you include the composer [autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading)somewhere in your codebase.

Examples
--------

[](#examples)

There are several examples provided in examples folder too

### Url To PDF (accessing site as bigger browser)

[](#url-to-pdf-accessing-site-as--bigger-browser)

```
use dawood\phpChrome\Chrome;

$chrome=new Chrome('https://youtube.com','/usr/bin/google-chrome');
$chrome->setOutputDirectory(__DIR__);
//not necessary to set window size
$chrome->setWindowSize($width=1477,$height=768);
print "Pdf successfully generated :".$chrome->getPdf().PHP_EOL;

```

### Url To PDF (accessing site as mobile browser)

[](#url-to-pdf-accessing-site-as--mobile-browser)

```
use dawood\phpChrome\Chrome;

$chrome=new Chrome('https://facebook.com','/usr/bin/google-chrome');
$chrome->setOutputDirectory(__DIR__);
$chrome->useMobileScreen();
//not necessary to set window size
$chrome->setWindowSize($width=768,$height=768);
print "Pdf successfully generated :".$chrome->getPdf().PHP_EOL;
```

### Take screenshot of url (accessing site as bigger browser)

[](#take-screenshot-of-url-accessing-site-as--bigger-browser)

```
use dawood\phpChrome\Chrome;

$chrome=new Chrome('https://facebook.com','/usr/bin/google-chrome');
$chrome->setOutputDirectory(__DIR__);
//not necessary to set window size
$chrome->setWindowSize($width=1366,$height=1024);
print "Image successfully generated :".$chrome->getScreenShot().PHP_EOL;

```

### Take screenshot of url (accessing site as mobile browser)

[](#take-screenshot-of-url-accessing-site-as--mobile-browser)

```
use dawood\phpChrome\Chrome;

$chrome=new Chrome('https://facebook.com','/usr/bin/google-chrome');
$chrome->setOutputDirectory(__DIR__);
$chrome->useMobileScreen();

//not necessary to set window size
$chrome->setWindowSize($width=768,$height=768);
print "Image successfully generated :".$chrome->getScreenShot().PHP_EOL;
```

### Take screenshot of Html File

[](#take-screenshot-of-html-file)

```
include '../vendor/autoload.php';

use dawood\phpChrome\Chrome;

$chrome=new Chrome(null,'/usr/bin/google-chrome');
$chrome->useHtmlFile(__DIR__.'/index.html');
print "Image successfully generated :".$chrome->getScreenShot().PHP_EOL;

```

### convert Html file to pdf

[](#convert-html-file-to-pdf)

```
include '../vendor/autoload.php';

use dawood\phpChrome\Chrome;

$chrome=new Chrome(null,'/usr/bin/google-chrome');
$chrome->useHtmlFile(__DIR__.'/index.html');
print "Pdf successfully generated :".$chrome->getPdf().PHP_EOL;
```

### convert Html code to pdf / screenshot

[](#convert-html-code-to-pdf--screenshot)

```
include '../vendor/autoload.php';

use dawood\phpChrome\Chrome;

$chrome=new Chrome(null,'/usr/bin/google-chrome');
$chrome->useHtml("I am test html");
print "Pdf successfully generated :".$chrome->getPdf().PHP_EOL;
print "screenShot successfully generated :".$chrome->getScreenShot().PHP_EOL;
```

### convert Html code to pdf / screenshot and save at desired location

[](#convert-html-code-to-pdf--screenshot-and-save-at-desired-location)

```
include '../vendor/autoload.php';

use dawood\phpChrome\Chrome;

$chrome=new Chrome(null,'/usr/bin/google-chrome');
$chrome->useHtml("I am test html");
print "Pdf successfully generated :".$chrome->getPdf("/tmp/mypdf.pdf").PHP_EOL;
print "screenShot successfully generated :".$chrome->getScreenShot("/tmp/hello/test.jpg").PHP_EOL;
```

Setting options
---------------

[](#setting-options)

The `google-chrome` shell command accepts different types of options: for complete list of options you can visit

### Wrapper Methods

[](#wrapper-methods)

- `constructor`: Accepts $url to visit(for pdf/screenshot) as first parameter you can pass this as null and later use `setUrl`, and second parameter is binary path of google-chrome installed in your system as second parameter if no binaryPath is provided is uses default location `/usr/bin/google-chrome`but you still can provide binary path later using `setBinaryPath`, constructor also put some default arguments like `headless , disable-gpu` which are necessary for google-chrome to work on cli
- `setBinaryPath` which accepts binary path and set it for you
- `setArguments` to set options of google-chrome it accepts array of options in a format

```
[
   $argument1=>$value1,
   $argument2=>$value2,
]

```

if your argument doesn't has values like `--headless` you can pass empty value e.g `[--headless=>'']`

- `setArgument` to set option of google-chrome it accepts two parameter $argument , $value if your argument doesn't has a value like `--headless` you can pass empty value e.g `setArgument('--headless','')`
- `setChromeDirectory` the directory where google-chrome will save your profile it is not mandatory as google-chrome by default uses some directory but in need you can use this method to change that
- `setUrl` to set the url to convert to pdf or to take screenshot
- `useHtmlFile` to use the file instead of url to convert to pdf or to take screenshot
- `useHtml` to use the html code instead of url to convert to pdf or to take screenshot
- `setOutputDirectory` directory to save the output (screenshots and pdf) the default directory is temporary directory of your operating system
- `getPdf` it receives optional path parameter to save the pdf file at if not provided it will save in output directory or temp directory of your operating system depending if you properly set up the output directory,
    for this check `setOutputDirectory` option,
    it will convert your provided url to pdf and return the location of newly saved pdf
- `getScreenShot` it receives optional path parameter to save the pdf file at if not provided it will save in output directory or temp directory of your operating system depending if you properly set up the output directory
    for this check `setOutputDirectory` option,
    it will take screenshot of your provided url and return the location of newly saved image
- `setWindowSize` you can set the chrome window size using this method it accepts two parameters $width and $height
- `useMobileScreen` ask chrome to access site as mobile browser
- `getArguments` returns all the arguments set

there are some other getters available too in case you need `getUrl , getBinaryPath , getOutputDirectory`

Installation of google-Chrome (linux/mac )
------------------------------------------

[](#installation-of-google-chrome-linuxmac-)

```
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'

sudo apt-get install libxss1 libappindicator1 libindicator7 libosmesa6

sudo apt-get update
sudo apt-get install -y google-chrome-stable

sudo ln -s /usr/lib/x86_64-linux-gnu/libOSMesa.so.6 /opt/google/chrome/libosmesa.so
```

then try running `google-chrome` from shell to verify it's installation

Installation of google-Chrome (Windows)
---------------------------------------

[](#installation-of-google-chrome-windows)

```
Just Install updated version of chrome(after V 61.*)
that-s it

```

then try running `C:\Program Files (x86)\Google\Chrome\Application>chrome.exe --headless` from cmd terminal to verify it's installation

> Note the path of chrome directory can be different in your case

License
-------

[](#license)

The **PhpChromeToPdf** is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

Contribution
------------

[](#contribution)

Thanks to all of the contributors ,
Check [Contribution](CONTRIBUTING.md) for contribution rules

Author
------

[](#author)

Dawood Ikhlaq and Open source community

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 88.6% 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 ~5 days

Total

4

Last Release

3220d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6933433cb8dc85ee0936f982f9f5c60a57563e4a61ff01fbe84e8334fdf57ab7?d=identicon)[daudmalik06](/maintainers/daudmalik06)

---

Top Contributors

[![daudmalik06](https://avatars.githubusercontent.com/u/3526480?v=4)](https://github.com/daudmalik06 "daudmalik06 (31 commits)")[![haroonmalik123](https://avatars.githubusercontent.com/u/30019395?v=4)](https://github.com/haroonmalik123 "haroonmalik123 (2 commits)")[![alexsoft](https://avatars.githubusercontent.com/u/1451894?v=4)](https://github.com/alexsoft "alexsoft (1 commits)")[![malikahsanraza5](https://avatars.githubusercontent.com/u/30020210?v=4)](https://github.com/malikahsanraza5 "malikahsanraza5 (1 commits)")

---

Tags

browsershotchromechromiumheadlessheadless-browsersheadless-chromelaravellaravel-frameworkpdfpdf-generationphpscreenshotsymfonyurl-to-imageurl-to-pdfphppdfshellchromescreenshots

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dawood-phpchromepdf/health.svg)

```
[![Health](https://phpackages.com/badges/dawood-phpchromepdf/health.svg)](https://phpackages.com/packages/dawood-phpchromepdf)
```

###  Alternatives

[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)[seregazhuk/php-watcher

Automatically restart PHP application once the source code changes

394137.8k4](/packages/seregazhuk-php-watcher)[alecrabbit/php-console-spinner

Extremely flexible spinner for \[async\] php cli applications

24032.0k2](/packages/alecrabbit-php-console-spinner)[ollyxar/php-malware-detector

PHP malware detector

12926.4k](/packages/ollyxar-php-malware-detector)[jyxo/php

Jyxo PHP Library

6460.8k](/packages/jyxo-php)[dawood/phpscreenrecorder

A slim PHP wrapper around ffmpeg to record screen,best for recording your acceptance test using selenium, easy to use and clean OOP interface

501.5k](/packages/dawood-phpscreenrecorder)

PHPackages © 2026

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