Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

Download PDF to a Specific Location on Button Press

$
0
0
from flask import Flask, render_template, request, send_filefrom werkzeug.utils import secure_filenamefrom pdf2docx import Converterapp = Flask(__name__)@app.route('/to-doc', methods=['POST', 'GET'])def pdfdoc():    docx_file = r"C:\Users\Achintha\Desktop\2nd Y 2\Flask\App\project\converted_documeneet.docx"    upload_success = False    converted_filename = "converted_document.docx"    if request.method == 'POST':        file = request.files['pdf']        filename = secure_filename(file.filename)        file.save(filename)        upload_success = True        cv = Converter(filename)        convert_File = cv.convert(docx_file)        if convert_File == "success":            return render_template('done.html', filename='converted_document.docx')    return render_template('pddoc.html', upload_success=upload_success)@app.route('/done/<filename>')def download(filename):    return send_file(filename, as_attachment=True)# debug modeif __name__ == '__main__':    app.run(debug=True)

when convert button press pdf convert to the document file, it works good . Now I want to add download button to download the doc file after complete,After file completely convert should go to the (done.html) file and on the site has the download button how to do this.


Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>