Pdfkit magic tool - will save the string as a pdf file

Pdfkit magic tool - will save the string as a pdf file


1, the installation kit

pip install pdfkit

2, on dry goods

import pdfkit

def create_pdf(str_data, to_file):
    '将字符串生成pdf文件' 
        # (需下载wkhtmltox)将程序路径传入config对象
    config = pdfkit.configuration(wkhtmltopdf=r"D:\Python\wkhtmltox\bin\wkhtmltopdf.exe")
        # 生成pdf文件,to_file为文件路径
    pdfkit.from_string(str_data, to_file, configuration=config)

create_pdf('Hello, World!', 'out.pdf')

3, look at the results:

Pdfkit magic tool - will save the string as a pdf file
Is not it simple!

Guess you like

Origin blog.51cto.com/14265713/2405084