Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response pdf flask #33

Open
matiasrebori opened this issue Sep 29, 2022 · 1 comment
Open

response pdf flask #33

matiasrebori opened this issue Sep 29, 2022 · 1 comment
Labels
enhancement New feature or request medium difficulty medium difficulty to implement

Comments

@matiasrebori
Copy link
Owner

make wrapper to return pdf from endpoint with flask

@matiasrebori matiasrebori added enhancement New feature or request medium difficulty medium difficulty to implement labels Sep 29, 2022
@matiasrebori
Copy link
Owner Author

matiasrebori commented Sep 29, 2022

from flask import make_response

def response_pdf(pdf: FPDF, name: str, title: str = None):
    """
    recibe un pdf, le asigna un nombre y un titulo y se prepara para enviar.

    :param pdf: objeto FPDF.
    :param name: nombre del archivo al descargar.
    :param title: titulo del archivo.
    :return:
    """
    title = name if title is None else title
    pdf.set_title(title)
    response = make_response(pdf.output())
    response.headers["Content-Type"] = "application/pdf"
    response.headers.set('Content-Disposition', f"inline; filename={name}.pdf")
    return response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request medium difficulty medium difficulty to implement
Projects
None yet
Development

No branches or pull requests

1 participant