您的位置:首页 > 编程语言 > Python开发

python--html to pdf

2016-06-17 00:00 447 查看
[code=language-bash]Debian/Ubuntu

To install wkhtmltopdf in a Debian/Ubuntu server, follow this steps(as root):

apt-get install wkhtmltopdf
apt-get install xvfb
echo -e '#!/bin/bash\nxvfb-run -a --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf -q $*' > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
wkhtmltopdf http://www.google.com output.pdf

then :

[code=language-python]pip install pdfkit

vim test.py

#coding:utf-8
#__author__:Bing
import pdfkit

pdfkit.from_file('test.html', 'out.pdf')

# Generating PDFs from strings and web-pages is equally easy:

pdfkit.from_string('Hello!', 'out.pdf')
pdfkit.from_url('http://google.com', 'out.pdf')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: