From d84019f18c1f928d628c48e087bce41933fc1860 Mon Sep 17 00:00:00 2001 From: yvesf Date: Sun, 21 Nov 2010 23:07:50 +0100 Subject: pdf -> jpeg mit convert/popen --- web.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'web.py') 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//", methods=["GET"]) def do_download_page(docnum,page): document = index.reader().stored_fields(docnum) -- cgit v1.2.1