Mercurial > odfcast > odfcast
diff odfcast/convert.py @ 19:2f627039d2b4
Add a MergeView to merge pdfs based on PyPDF2
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Mon, 29 Sep 2014 15:59:36 +0200 |
parents | 585904e7411a |
children | 0e40926735e1 |
line wrap: on
line diff
--- a/odfcast/convert.py Mon Sep 29 14:18:11 2014 +0200 +++ b/odfcast/convert.py Mon Sep 29 15:59:36 2014 +0200 @@ -7,14 +7,19 @@ from py3o.template import Template +from PyPDF2 import PdfFileMerger + + ALLOWED_FORMATS = ["pdf", "doc", "docx", "odt"] +PDF_MIMETYPE = "application/pdf" + MIMETYPES = { "odt": "application/vnd.oasis.opendocument.text", "doc": "application/msword", "docx": "application/vnd.openxmlformats-officedocument" ".wordprocessingml.document", - "pdf": "application/pdf", + "pdf": PDF_MIMETYPE, } DEFAULT_MIMETYPE = "application/octet-stream" @@ -92,3 +97,23 @@ def get(self): return render_template("template_convert.html") + + +class MergeView(MethodView): + + def get(self): + return render_template("merge.html") + + def post(self): + merger = PdfFileMerger() + ffiles = request.files.getlist('files') + + for ffile in ffiles: + merger.append(ffile) + + outfile = tempfile.NamedTemporaryFile() + + merger.write(outfile.name) + + merger.close() + return Response(outfile, mimetype=PDF_MIMETYPE)