-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (27 loc) · 888 Bytes
/
Copy pathapp.py
File metadata and controls
33 lines (27 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import glob
import shlex
import subprocess
import sys
import uuid
from flask import Flask, request, send_file
app = Flask(__name__)
@app.route('/')
def index():
url = request.args.get('url', '')
if not url.strip():
return '''
<form action="/" method="get">
URL: <input type="text" name="url">
<input type="submit" value="Download PDF">
</form>
'''
else:
filename = '/tmp/{}.pdf'.format(uuid.uuid4())
command = '/app/bin/wkhtmltopdf "{}" "{}"'.format(url, filename)
process = subprocess.Popen(shlex.split(command),
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
process.wait()
return send_file(filename,
as_attachment=True,
mimetype='application/pdf')