python制作pdf电子书
准备
安装wkhtmltopdf
python安装依赖包
pdfkit的用法
初级了解函数
进阶
options
options = {
'page-size': 'Letter',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': "UTF-8",
'custom-header': [
('Accept-Encoding', 'gzip')
],
'cookie': [
('cookie-name1', 'cookie-value1'),
('cookie-name2', 'cookie-value2'),
],
'outline-depth': 10,
}
cover
options = {
'page-size': 'Letter',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
'encoding': "UTF-8",
'custom-header': [
('Accept-Encoding', 'gzip')
],
'cookie': [
('cookie-name1', 'cookie-value1'),
('cookie-name2', 'cookie-value2'),
],
'outline-depth': 10,
}
cover='demo.html'
pdfkit.from_file('demo.html','demo.pdf',cover=cover,options=options)
css
css='demo.css'
pdfkit.from_file('demo.html','demo.pdf',options=options,cover=cover,css=css)
注意
import sys
import threading
reload(sys)
sys.setdefaultencoding('utf8')
实战
注意
参考文章