html 转pdf 推荐 9 Convert HTML to PDF using Webkit (QtWebKit)

wkhtmltopdf google.pdf

xhtml2pdf 3

sudo apt-get install wkhtmltopdf


CSS代码:style="page-break-before:always;” 控制打印是否分页  
--header-html 页眉  
--footer-html 页脚  
--header-spacing 页眉距内容距离  
--footer-spacing 页脚距内容距离  
wkhtmltopdf -T 15mm --header-spacing 5 --outline cover --header-html a.html --header-line --footer-center "[page]/[topage]" --footer-line toc --toc-header-text "目录" t2.pdf 
/usr/local/bin/wkhtmltopdf -T 15mm --header-spacing 5 --header-html header.html --footer-right "[page]/[toPage]"  --outline cover cover.html eoe-wiki-slug-23.pdf 


wkhtmltopdf --javascript-delay 1000 --page-size Letter --encoding utf-8 --print-media-type --disable-external-links --image-quality 100 --margin-left 5mm --margin-right 5mm --margin-top 5mm --margin-bottom 5mm

wkhtmltopdf: cannot connect to X server

1. Download wkhtmltopdf.
2. Extract it and move it to /usr/bin/
3. Rename it to wkhtmltopdf so that now you have an executable at /usr/bin/wkhtmltopdf
4. Set permissions: sudo chmod a+x /usr/bin/wkhtmltopdf
4. Install required support packages. sudo apt-get install openssl build-essential xorg libssl-dev
5. Check to see if it works: run wkhtmltopdf test.pdf. If it works, then you are done -- make sure to make a symbolic link as per INSTRUCTIONS.txt. If you get the error "Cannot connect to X server" then continue to number 6.
6. We need to run it headless on a 'virtual' x server. We will do this with a package called xvfb. sudo apt-get install xvfb
7. We need to write a little shell script to wrap wkhtmltopdf in xvfb. Make a file called and add the following:
xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf $*
8. Move this shell script to /usr/bin, and set permissions: sudo chmod a+x /usr/bin/
9. Finally, make your symbolic link in /sites/all/modules/print/lib. Command is ln -s /usr/bin/ wkhtmltopdf
xvfb-run wkhtmltoimage --format png --quality 100 --no-debug-javascript --height 800 fb.png