import pdfkit
# 类似于selenium的webdriver,必须要下载然后添加到环境变量里面去
path_wk = r'C:\python37\wkhtmltopdf\bin\wkhtmltopdf.exe'
# 指定wkhtmltopdf=path_wk
cOnfig= pdfkit.configuration(wkhtmltopdf=path_wk)
# 可以直接将本地的html文件,转成pdf
pdfkit.from_file("1.html", "1.pdf", cOnfiguration=config)
# 可以传入一个url,将该url对应的html转成pdf
pdfkit.from_url("https://www.baidu.com", "baidu.pdf", cOnfiguration=config)
# 也可以将一个字符串转成pdf
pdfkit.from_string("hello world", "hello.pdf", cOnfiguration=config)