【发布时间】:2015-04-01 10:28:05
【问题描述】:
这个问题真的很简单,但是我找不到任何关于它的数据。 当我使用reportlab 生成pdf 时,将httpresponse 作为文件传递,配置为显示文件的浏览器会正确显示pdf。但是,选项卡的标题仍然是“(匿名)127.0.0.1/whatnot”,这对用户来说有点难看。
由于大多数网站都能够以某种方式显示适当的标题,我认为这是可行的...是否有某种标题参数可以传递给 pdf?或者响应的一些标题?这是我的代码:
def render_pdf_report(self, context, file_name):
response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'filename="{}"'.format(file_name)
document = BaseDocTemplate(response, **self.get_create_document_kwargs())
# pdf generation code
document.build(story)
return response
【问题讨论】:
-
你能提供任何网站的例子吗?
-
例如:这里,文件名显示在标题biblioteca.org.ar/libros/211756.pdf中。此外,当使用 weasyprint 生成时,会处理 html 标题标签,所以我很肯定它是可行的
标签: python django pdf-generation httpresponse reportlab