fix: Don't send attachment/download header with PDF files (#6881)
This commit is contained in:
parent
492252a5b3
commit
1bb4c6275f
2 changed files with 10 additions and 2 deletions
|
|
@ -90,13 +90,13 @@ def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0):
|
|||
html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead)
|
||||
frappe.local.response.filename = "{name}.pdf".format(name=name.replace(" ", "-").replace("/", "-"))
|
||||
frappe.local.response.filecontent = get_pdf(html)
|
||||
frappe.local.response.type = "download"
|
||||
frappe.local.response.type = "pdf"
|
||||
|
||||
@frappe.whitelist()
|
||||
def report_to_pdf(html, orientation="Landscape"):
|
||||
frappe.local.response.filename = "report.pdf"
|
||||
frappe.local.response.filecontent = get_pdf(html, {"orientation": orientation})
|
||||
frappe.local.response.type = "download"
|
||||
frappe.local.response.type = "pdf"
|
||||
|
||||
@frappe.whitelist()
|
||||
def print_by_server(doctype, name, print_format=None, doc=None, no_letterhead=0):
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ def build_response(response_type=None):
|
|||
'txt': as_txt,
|
||||
'download': as_raw,
|
||||
'json': as_json,
|
||||
'pdf': as_pdf,
|
||||
'page': as_page,
|
||||
'redirect': redirect,
|
||||
'binary': as_binary
|
||||
|
|
@ -84,6 +85,13 @@ def as_json():
|
|||
response.data = json.dumps(frappe.local.response, default=json_handler, separators=(',',':'))
|
||||
return response
|
||||
|
||||
def as_pdf():
|
||||
response = Response()
|
||||
response.mimetype = "application/pdf"
|
||||
response.headers["Content-Disposition"] = ("filename=\"%s\"" % frappe.response['filename'].replace(' ', '_')).encode("utf-8")
|
||||
response.data = frappe.response['filecontent']
|
||||
return response
|
||||
|
||||
def as_binary():
|
||||
response = Response()
|
||||
response.mimetype = 'application/octet-stream'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue