1.安装wkhtmltopdf
sudo apt install wkhtmltopdf
2.安装pip包
pip3 install pdfkit
3.代码实现
# -*- coding: utf-8 -*- from odoo import http import pdfkit class FsnPlan(http.Controller): @http.route('/test/download_pdf/', auth='public') def test_download_pdf(self, **kw): html = "<h1>Hello World !!!哈哈哈</h1>" attachment = pdfkit.from_string( html, options={ 'page-size': 'A4', 'margin-top': '0', 'margin-right': '0', 'margin-left': '0', 'margin-bottom': '0', 'zoom': '1.2', 'encoding': "UTF-8", }) response = http.request.make_response(attachment) response.headers['Content-type'] = 'application/pdf' # 指定返回的类型 response.headers["Content-Disposition"] = "inline; filename=output.pdf" # 文件名称 return response
标签:pdfkit,http,Odoo14,pdf,margin,response,下载 From: https://www.cnblogs.com/wangdianchao/p/17151354.html