pdfkit安装使用

 

centos 安装pdfkit
1、先安装pdfkit依赖包 wkhtmltopdf
安装方式:
# wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm
# yum localinstall wkhtmltox-0.12.2.1_linux-centos6-amd64.rpm # 安装后会自动加入到环境变量中
2、安装pdfkit
# pip install pdfkit
3、安装wkhtmltopdf(如报错 /usr/local/bin/wkhtmltopdf: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory)
yum install libpng12

windows可以下载win版本的wkhtmltopdf, 下载地址:http://wkhtmltopdf.org/downloads.html


########################## windows code ##############################
import pdfkit

config = pdfkit.configuration(wkhtmltopdf='C:\wkhtmltopdf\wkhtmltopdf.exe')
options = {
'page-size': 'Letter',
'margin-top': '0.1in',
'margin-right': '0.1in',
'margin-bottom': '0.1in',
'margin-left': '0.1in',
'encoding': "UTF-8",
}
html = "<html><body>hello</body></html>"
pdfkit.from_string(html,"html.pdf",configuration=config, options=options)

# url = "http://www.baidu.com"
# pdfkit.from_string(url,"html.pdf",configuration=config, options=options)

 

########################## linux code ##############################
import pdfkit

html = "<html><body>hello</body></html>"
pdfkit.from_string(html, "html.pdf")

########################################################

 

posted @ 2015-11-05 10:51  weiokx  阅读(3104)  评论(0编辑  收藏  举报