# -*- encoding: utf-8 -*- # ----------------------------------------------------------------------------- # @File Name : html_to_pdf.py # @Time : 2020/11/19 上午11:07 # @Author : X. Peng # @Email : acepengxiong@163.com # @Software : PyCharm # ----------------------------------------------------------------------------- import pdfkit def html_to_pdf(): options = { 'encoding': "utf-8", # 'page-size': 'A5', 'page-width': '300mm', 'page-height': '[200mm,100mm,50mm]', 'margin-top': '0mm', 'margin-right': '0mm', 'margin-bottom': '0mm', 'margin-left': '0mm' } pdfkit.from_url('https://www.taobao.com', '/Users/pengxiong/Desktop/out.pdf', options=options) if __name__ == '__main__': html_to_pdf()