# HG changeset patch # User Björn Ricks # Date 1411999176 -7200 # Node ID 2f627039d2b4106714455873826e9c2657e40a33 # Parent 585904e7411a1c86f6b24f3af8f99e1016023113 Add a MergeView to merge pdfs based on PyPDF2 diff -r 585904e7411a -r 2f627039d2b4 odfcast/convert.py --- 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) diff -r 585904e7411a -r 2f627039d2b4 templates/merge.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/merge.html Mon Sep 29 15:59:36 2014 +0200 @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} +

Merge

+ +
+
+ + +
+ +
+{% endblock %}