Skip to content

Commit

Permalink
Allow filename with non ascii characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0tonic committed Nov 14, 2024
1 parent b3182cd commit f5c2299
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions flask_weasyprint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Make PDF in your Flask app with WeasyPrint."""

from io import BytesIO
from urllib.parse import urljoin, urlsplit

from flask import current_app, has_request_context, request
from flask import current_app, has_request_context, request, send_file
from werkzeug.test import Client, ClientRedirectError, EnvironBuilder
from werkzeug.wrappers import Response

Expand Down Expand Up @@ -196,10 +197,9 @@ def render_pdf(html, stylesheets=None, download_filename=None,
if not hasattr(html, 'write_pdf'):
html = HTML(html)
pdf = html.write_pdf(stylesheets=stylesheets, **options)
response = current_app.response_class(pdf, mimetype='application/pdf')
if download_filename:
response.headers.add(
'Content-Disposition',
'attachment' if automatic_download else 'inline',
filename=download_filename)
return response
return send_file(
BytesIO(pdf),
mimetype="application/pdf",
as_attachment=automatic_download,
download_name=download_filename,
)

0 comments on commit f5c2299

Please sign in to comment.