fbpx

How to render HTML into PDF files

How to render HTML into PDF files

wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the QT Webkit rendering engine. These run entirely “headless” and do not require a display or display service.
Install wkhtmltopdf and its requried packages

sudo apt-get install wkhtmltopdf
sudo ln -s /usr/bin/wkhtmltopdf /usr/local/bin/html2pdf
sudo apt-get install xvfb
apt-get install libicu48

Generate pdf files from html by this command

xvfb-run html2pdf --margin-left 0mm --margin-right 0mm --margin-top 0mm --margin-bottom 0mm --orientation Portrait --page-size A4 http://domain_name.com/test.php /var/www/pdf_file.pdf

 
 
 

Share this post