首页 > 其他分享 >Odoo14_pdf下载功能实现

Odoo14_pdf下载功能实现

时间:2023-02-24 14:33:52浏览次数:38  
标签:pdfkit http Odoo14 pdf margin response 下载

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

相关文章