Laravel Export Html To PDF
Aug 26, 2017
Export Datas To PDF
There have a package wkhtmltopdf using webkit(QTwebkit) convert html to pdf or image from commandline.
For Laravel: laravel-snappy
Installation is same as all other laravel package (can check git repository docs).
After installation, We need config the file config/snappy.php
.
My configuration:
The parameter ‘binary’ is the excutable file which download from https://wkhtmltopdf.org/downloads.html
There have three version of linux,mac,windows. for mac os it’s an installation package, we need install it to mac os.After the bin path is /usr/local/bin/wkhtmltopdf
.
Finally, the laravel code
Load view file load the laravel view file, and can pass data to the view. view file is a html file, we can add any style to the file, pdf view export as html file.
Notice PDF won’t have much width. so if the cotent is to large. We need use small font-size, otherwise page will not fully show in PDF