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

python html格式的pdf转换成pdf文件

2016-03-25 16:29 1036 查看
今天对接物流接口时,遇到返回来的面单是个网页版的pdf,经过一番波折后,借用python中的pdfkit解决了这个问题:

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

但是还存在一个问题,pdf文件中面单占的大小不能控制,待解决。

后续:

options = {

                        'page-width': '120',

                        'page-height': '170',

                        'margin-top': '0.1',

                        'margin-right': '0.1',

                        'margin-left': '0.1',

                        'margin-bottom': '0.1',

                    }

config = pdfkit.configuration(wkhtmltopdf='/home/newpro/pro/wkhtmltopdf')

pdfkit.from_string('test.html', 'test.pdf', options=options, configuration=config)

                       

通过传入options来截取对应纬度所需的信息。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: