0

I have a flask page that downloads a PDF as part of the return statement, but I'd also like to return some text to display on the website. Is it possible to return two things, such as?:

return send_file('test.pdf', as_attachment=True), "this is what the webpage displays"

I have also tried it as a separate function, but nothing downloads. The download works fine if I remove just use this as part of the pdf() function:

 return send_file('test.pdf', as_attachment=True)

Full code:

from reportlab.lib.enums import TA_JUSTIFY
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from flask import Flask, send_file


app = Flask(__name__)
@app.route('/')
def pdf():

    global doc
    doc = SimpleDocTemplate("test.pdf",pagesize=letter)
    Story=[]

    styles=getSampleStyleSheet()
    styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
    ptext = '<font size=12>test</font>'

    Story.append(Paragraph(ptext, styles["Justify"]))

    doc.build(Story)

    def download():
        global doc
        return send_file('test.pdf', as_attachment=True)

    download()
    return "this is what the webpage displays"
app.run()
user2242044
  • 8,803
  • 25
  • 97
  • 164
  • What about returning a webpage and requesting the PDF file via JavaScript through this webpage e.g. via jQuery's `$(document).ready()`? – albert Nov 30 '15 at 15:34
  • @albert it sounds like a fine idea, but I know nothing about JavaScript – user2242044 Nov 30 '15 at 15:50
  • I am just a beginner using JavaScript and I am not absolutely sure about how to do this since I receive some error message on the console. However, googling should give you further hints. Sorry for that... – albert Nov 30 '15 at 17:35

0 Answers0