|
1 | 1 | PHPHeadlessChrome
|
2 | 2 | ===============
|
3 | 3 |
|
| 4 | +[](https://packagist.org/packages/daandesmedt/phpheadlesschrome) |
| 5 | +[](https://packagist.org/packages/daandesmedt/phpheadlesschrome) |
| 6 | +[](https://packagist.org/packages/daandesmedt/phpheadlesschrome) |
| 7 | + |
| 8 | + |
4 | 9 | Headless Chrome is shipping in Chrome 59. It's a way to run the Chrome browser in a headless environment. Essentially, running Chrome without chrome! It brings all modern web platform features provided by Chromium and the Blink rendering engine to the command line.
|
5 | 10 |
|
6 | 11 | PHPHeadlessChrome provides a simple usage helper class to create PDF and / or screenshots using Headless Chrome.
|
@@ -103,4 +108,56 @@ $headlessChromer->setHTML('<h1>Headless Chrome PHP example</h1><h3>HTML to PDF</
|
103 | 108 | $headlessChromer->toScreenShot('output.jpg');
|
104 | 109 |
|
105 | 110 | print 'Screenshot saved to : ' . $headlessChromer->getFilePath();
|
| 111 | +``` |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +## HTML local file to PDF |
| 116 | + |
| 117 | +```php |
| 118 | +<?php |
| 119 | + |
| 120 | +require __DIR__ . '/../vendor/autoload.php'; |
| 121 | + |
| 122 | +use daandesmedt\PHPHeadlessChrome\HeadlessChrome; |
| 123 | + |
| 124 | +$headlessChromer = new HeadlessChrome(); |
| 125 | +$headlessChromer->setBinaryPath('C:\Program Files (x86)\Google\Chrome\Application\chrome'); |
| 126 | +$headlessChromer->setOutputDirectory(__DIR__); |
| 127 | +$headlessChromer->setHTMLFile(__DIR__ . '\assets\HTMLFile.html'); |
| 128 | +$headlessChromer->toPDF('output.pdf'); |
| 129 | + |
| 130 | +print 'PDF generated to : ' . $headlessChromer->getFilePath(); |
| 131 | +``` |
| 132 | + |
| 133 | + |
| 134 | +## HTML local file to Screenshot (image) |
| 135 | + |
| 136 | +```php |
| 137 | +<?php |
| 138 | + |
| 139 | +require __DIR__ . '/../vendor/autoload.php'; |
| 140 | + |
| 141 | +use daandesmedt\PHPHeadlessChrome\HeadlessChrome; |
| 142 | + |
| 143 | +$headlessChromer = new HeadlessChrome(); |
| 144 | +$headlessChromer->setBinaryPath('C:\Program Files (x86)\Google\Chrome\Application\chrome'); |
| 145 | +$headlessChromer->setOutputDirectory(__DIR__); |
| 146 | +$headlessChromer->setHTMLFile(__DIR__ . '\assets\HTMLFile.html'); |
| 147 | +$headlessChromer->toScreenShot('output.jpg'); |
| 148 | + |
| 149 | +print 'Screenshot saved to : ' . $headlessChromer->getFilePath(); |
| 150 | +``` |
| 151 | + |
| 152 | + |
| 153 | +## Set mobile mode |
| 154 | + |
| 155 | +```php |
| 156 | +$headlessChromer->useMobile(); |
| 157 | +``` |
| 158 | + |
| 159 | +## Set window size |
| 160 | + |
| 161 | +```php |
| 162 | +$headlessChromer->setWindowSize(375, 667); |
106 | 163 | ```
|
0 commit comments