summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorMehul Patel <mep@odoo.com>2017-08-14 14:23:50 +0200
committerRichard Mathot <rim@odoo.com>2017-08-14 14:23:50 +0200
commitf205bfcd4ddcf3f1d8676ee87ee0b29941bd6773 (patch)
treeda13f360ee4174ed03d849f5fe86c06fad96734e /odoo
parentcd05983121e4edef7db8d46b7e29585857d03a80 (diff)
[ADD] tools: utility to merge pdf files
Diffstat (limited to 'odoo')
-rw-r--r--odoo/tools/__init__.py1
-rw-r--r--odoo/tools/pdf.py21
2 files changed, 22 insertions, 0 deletions
diff --git a/odoo/tools/__init__.py b/odoo/tools/__init__.py
index ab9b57b348c..4eb84a9de16 100644
--- a/odoo/tools/__init__.py
+++ b/odoo/tools/__init__.py
@@ -4,6 +4,7 @@
import copy
from . import win32
from . import appdirs
+from . import pdf
from .config import config
from .misc import *
from .convert import *
diff --git a/odoo/tools/pdf.py b/odoo/tools/pdf.py
new file mode 100644
index 00000000000..7f6f244ce45
--- /dev/null
+++ b/odoo/tools/pdf.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from cStringIO import StringIO
+from PyPDF2 import PdfFileWriter, PdfFileReader
+
+
+def merge_pdf(pdf_data):
+ ''' Merge a collection of PDF documents in one
+ :param list pdf_data: a list of PDF datastrings
+ :return: a unique merged PDF datastring
+ '''
+ writer = PdfFileWriter()
+ for document in pdf_data:
+ reader = PdfFileReader(StringIO(document), strict=False)
+ for page in range(0, reader.getNumPages()):
+ writer.addPage(reader.getPage(page))
+ _buffer = StringIO()
+ writer.write(_buffer)
+ merged_pdf = _buffer.getvalue()
+ _buffer.close()
+ return merged_pdf