[ADD] tools: utility to merge pdf files

This commit is contained in:
Mehul Patel
2017-08-14 14:23:50 +02:00
committed by Richard Mathot
parent cd05983121
commit f205bfcd4d
2 changed files with 22 additions and 0 deletions
+1
View File
@@ -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 *
+21
View File
@@ -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