summaryrefslogtreecommitdiff
path: root/web.py
diff options
context:
space:
mode:
authoryvesf <yvesf-git@xapek.org>2010-11-21 23:07:50 +0100
committeryvesf <yvesf-git@xapek.org>2010-11-21 23:07:50 +0100
commitd84019f18c1f928d628c48e087bce41933fc1860 (patch)
treea596a33c6f18db1711877e2c02c5bf3588b27f02 /web.py
parent1c34f8b6824b38c5a2698bbbd27a7aa7df51da9c (diff)
downloadbooksearch-d84019f18c1f928d628c48e087bce41933fc1860.tar.gz
booksearch-d84019f18c1f928d628c48e087bce41933fc1860.zip
pdf -> jpeg mit convert/popen
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)