PHP code example of daandesmedt / phpheadlesschrome
1. Go to this page and download the library: Download daandesmedt/phpheadlesschrome library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daandesmedt / phpheadlesschrome example snippets
andesmedt\PHPHeadlessChrome\HeadlessChrome;
$headlessChromer = new HeadlessChrome();
$headlessChromer->setUrl('http://www.google.be');
$headlessChromer->setBinaryPath('C:\Program Files (x86)\Google\Chrome\Application\chrome');
$headlessChromer->setOutputDirectory(__DIR__);
$headlessChromer->toPDF('output.pdf');
print 'PDF generated to : ' . $headlessChromer->getFilePath();
andesmedt\PHPHeadlessChrome\HeadlessChrome;
$headlessChromer = new HeadlessChrome();
$headlessChromer->setUrl('http://www.google.be');
$headlessChromer->setBinaryPath('C:\Program Files (x86)\Google\Chrome\Application\chrome');
$headlessChromer->setOutputDirectory(__DIR__);
$headlessChromer->toScreenShot('output.jpg');
print 'Screenshot saved to : ' . $headlessChromer->getFilePath();
andesmedt\PHPHeadlessChrome\HeadlessChrome;
$headlessChromer = new HeadlessChrome();
$headlessChromer->setBinaryPath('C:\Program Files (x86)\Google\Chrome\Application\chrome');
$headlessChromer->setOutputDirectory(__DIR__);
$headlessChromer->setHTML('<h1>Headless Chrome PHP example</h1><h3>HTML to PDF</h3>');
$headlessChromer->toPDF('output.pdf');
print 'PDF generated to : ' . $headlessChromer->getFilePath();
andesmedt\PHPHeadlessChrome\HeadlessChrome;
$headlessChromer = new HeadlessChrome();
$headlessChromer->setBinaryPath('C:\Program Files (x86)\Google\Chrome\Application\chrome');
$headlessChromer->setOutputDirectory(__DIR__);
$headlessChromer->setHTML('<h1>Headless Chrome PHP example</h1><h3>HTML to PDF</h3>');
$headlessChromer->toScreenShot('output.jpg');
print 'Screenshot saved to : ' . $headlessChromer->getFilePath();