Download the PHP package dawood/phpchromepdf without Composer
On this page you can find all versions of the php package dawood/phpchromepdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpchromepdf
PHP ChromeToPdf
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.
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 )
This package supports Laravel. Install it in a Laravel application as follows:
done.
Installation ( Simple PHP App )
Install the package through composer:
Make sure, that you include the composer autoloader somewhere in your codebase.
Examples
There are several examples provided in examples folder too
Url To PDF (accessing site as bigger browser)
Url To PDF (accessing site as mobile browser)
Take screenshot of url (accessing site as bigger browser)
Take screenshot of url (accessing site as mobile browser)
Take screenshot of Html File
convert Html file to pdf
convert Html code to pdf / screenshot
convert Html code to pdf / screenshot and save at desired location
Setting options
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/
Wrapper Methods
constructor
: Accepts $url to visit(for pdf/screenshot) as first parameter you can pass this as null and later usesetUrl
, 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 usingsetBinaryPath
, constructor also put some default arguments likeheadless , disable-gpu
which are necessary for google-chrome to work on clisetBinaryPath
which accepts binary path and set it for yousetArguments
to set options of google-chrome it accepts array of options in a format
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.gsetArgument('--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 checksetOutputDirectory
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 checksetOutputDirectory
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 )
then try running google-chrome
from shell to verify it's installation
Installation of google-Chrome (Windows)
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
The PhpChromeToPdf is open-sourced software licensed under the MIT license.
Contribution
Thanks to all of the contributors ,
Check Contribution for contribution rules
Author
Dawood Ikhlaq and Open source community