summaryrefslogtreecommitdiff
path: root/web.py
diff options
context:
space:
mode:
Diffstat (limited to 'web.py')
-rw-r--r--web.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/web.py b/web.py
index 577e56f..dc1632e 100644
--- a/web.py
+++ b/web.py
@@ -13,6 +13,7 @@ import whoosh.query as query
import flask
import pyPdf
import werkzeug
+import subprocess
app = flask.Flask("booksearch")
@@ -31,6 +32,27 @@ def do_download_file(docnum):
filename=os.path.basename(document['path']))
return r
+@app.route("/test")
+def test():
+ input = pyPdf.PdfFileReader(file("test.pdf", 'r'))
+ page = input.getPage(0)
+ out = pyPdf.PdfFileWriter()
+ out.addPage(page)
+ pdffile = StringIO()
+ out.write(pdffile)
+ process = subprocess.Popen(["/usr/bin/convert", "pdf:-", "jpeg:-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ outjpg = StringIO()
+ pdffile.seek(0)
+ while not process.stdin.closed:
+ print "."
+ stdout, stderr = process.communicate(pdffile.read())
+ if not stdout:
+ break
+ outjpg.write(stdout)
+ outjpg.seek(0)
+ r = werkzeug.Response(outjpg, mimetype="image/jpeg")
+ return r
+
@app.route("/download/page/<int:docnum>/<int:page>", methods=["GET"])
def do_download_page(docnum,page):
document = index.reader().stored_fields(docnum)