Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 513 | All time: 5,743 This week: 86 |
Version | License | PHP version | Categories | |||
phpchrometopdf 1.0.3 | MIT/X Consortium ... | 5 | HTML, PHP 5, Graphics, Files and Folders |
Description | Author | |||
This class can generate PDF or images of HTML pages with Chrome(headless). Innovation Award
|
What is the best PHP pdf creation class?
CREATE PDF
What is the best PHP pdf to image class?
Need to convert PDF file to image
<?php |
PHP ChromeToPdf provides a simple and clean interface to ease PDF and image creation with
Google Chrome. The Google Chrome
must be installed and working on your system. See the section below for details.
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
Install the package through composer:
composer require dawood/phpchromepdf
Make sure, that you include the composer autoloader somewhere in your codebase.
There are several examples provided in examples folder too
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;
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;
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;
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;
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;
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;
include '../vendor/autoload.php';
use dawood\phpChrome\Chrome;
$chrome=new Chrome(null,'/usr/bin/google-chrome');
$chrome->useHtml("<h2>I am test html</h2>");
print "Pdf successfully generated :".$chrome->getPdf().PHP_EOL;
print "screenShot successfully generated :".$chrome->getScreenShot().PHP_EOL;
include '../vendor/autoload.php';
use dawood\phpChrome\Chrome;
$chrome=new Chrome(null,'/usr/bin/google-chrome');
$chrome->useHtml("<h2>I am test html</h2>");
print "Pdf successfully generated :".$chrome->getPdf("/tmp/mypdf.pdf").PHP_EOL;
print "screenShot successfully generated :".$chrome->getScreenShot("/tmp/hello/test.jpg").PHP_EOL;
The google-chrome
shell command accepts different types of options:
for complete list of options you can visit
https://peter.sh/experiments/chromium-command-line-switches/
* 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','')
there are some other getters available too in case you need
getUrl , getBinaryPath , getOutputDirectory
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
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
The PhpChromeToPdf is open-sourced software licensed under the MIT license.
Thanks to all of the contributors , Check Contribution for contribution rules
Dawood Ikhlaq and Open source community
Files (17) |
File | Role | Description | ||
---|---|---|---|---|
examples (9 files) | ||||
src (1 file) | ||||
tests (2 files) | ||||
.styleci.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONTRIBUTING.md | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files (17) | / | examples |
File | Role | Description |
---|---|---|
index.html | Data | Auxiliary data |
pdf.php | Example | Example script |
pdfFromHtmlCode.php | Example | Example script |
pdfFromHtmlFile.php | Example | Example script |
pdfInDefaultDirectory.php | Example | Example script |
pdfMobileScreen.php | Example | Example script |
screenshot.php | Example | Example script |
screenshotFromHtmlFile.php | Example | Example script |
screenShotMobileScreen.php | Example | Example script |
Files (17) | / | tests |
File | Role | Description |
---|---|---|
bootstrap.php | Aux. | Auxiliary script |
ChromeTestSuite.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.