I'm trying to get pdf from web but when I click the button to render the pdf, I get the error : the file is in text/plain. Here is the code:
@http.route('/comande/suivi/<int:orderid>', type='http', auth='user', website=True)
def print_suivi(self, orderid, **kw):
pdf = request.env.ref('modul_name.report_model_name').report_action(orderid, data={'order': orderid})
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)),
('Content-Disposition', 'attachment; filename="report.pdf"')]
return request.make_response(pdf, headers=pdfhttpheaders)`
Can you help me? Thank you
After adding render_qweb_pdf()
you don't need to use report_action()
method. Try to do something like this :
pdf_report = request.env['report.module_name.report_template_name']
pdf, _ = request.env.ref('module_name.report_name').sudo().with_context().render_qweb_pdf(pdf_report)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)