python html内容转写到pdf文件

pip install pdfkit
import pdfkit
import os


def html_to_pdf(content_html, save_path):
    """html转pdf,save_path为pdf绝对路径"""
    os.makedirs(os.path.dirname(save_path), exist_ok=True)
    pdfkit.from_string(content_html, save_path, options={'encoding': "UTF-8", 'enable-local-file-access': True})
posted @ 2025-01-11 10:43  二月雪  阅读(80)  评论(0)    收藏  举报