我通过以下方式在我的 django 应用程序中生成 PDF 文件:
context = Context({'data':data_object, 'MEDIA_ROOT':settings.MEDIA_ROOT})
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode('UTF-8')), result)
if not pdf.err:
response = HttpResponse( result.getvalue() )
response['Content-Type'] = 'application/pdf'
response['Content-Disposition'] = 'attachment; filename="%s.pdf"'%(title)
return response
当用户想要下载 PDF 文件时,它的效果很好。但是,我需要在电子邮件中附加此 PDF。这就是为什么我需要获取此 PDF 的内容。我在 xhtml2pdf 文档中找不到任何内容。你能帮我解决它吗?