第一步: 安装wkhtmltox.exe 第二步 配置环境变量path C:\Program Files\wkhtmltopdf\bin 第三步: import pdfkit from django.template.loader import get_template real_name = 'abc' card = '123456' data = {'name': real_name, 'port_card': card} options = { 'page-size': 'A3', 'margin-top': '0.75in', 'margin-right': '0.75in', 'margin-bottom': '0.75in', 'margin-left': '0.75in', 'encoding': "UTF-8", 'no-outline': None } template = get_template('retouch_contract.html') s = time.time() html = template.render(data) pdfkit.from_string(html, "upload/file/{}.pdf".format(str(s)), options=options) retoucher.retouch_contract = "upload/file/{}.pdf".format(str(s))
django动态转html为pdf保存在本地
最新推荐文章于 2023-03-11 00:15:00 发布