Commit 52100292 authored by Jérome Perrin's avatar Jérome Perrin

pdf_merge: py3

parent 78729081
...@@ -35,20 +35,20 @@ def mergePDFList(self, pdf_data_list, start_on_recto=False): ...@@ -35,20 +35,20 @@ def mergePDFList(self, pdf_data_list, start_on_recto=False):
to have each PDF as the recto page. This is useful if you have to print the to have each PDF as the recto page. This is useful if you have to print the
merged pdf in recto/verso mode. merged pdf in recto/verso mode.
""" """
from six.moves import cStringIO as StringIO from io import BytesIO
from PyPDF2 import PdfFileWriter, PdfFileReader from PyPDF2 import PdfFileWriter, PdfFileReader
output = PdfFileWriter() output = PdfFileWriter()
for pdf_data in pdf_data_list: for pdf_data in pdf_data_list:
if pdf_data: if pdf_data:
pdf_reader = PdfFileReader(StringIO(pdf_data)) pdf_reader = PdfFileReader(BytesIO(pdf_data))
page_count = pdf_reader.getNumPages() page_count = pdf_reader.getNumPages()
for page in range(page_count): for page in range(page_count):
output.addPage(pdf_reader.getPage(page)) output.addPage(pdf_reader.getPage(page))
if start_on_recto and page_count % 2: if start_on_recto and page_count % 2:
output.addBlankPage() output.addBlankPage()
outputStream = StringIO() outputStream = BytesIO()
output.write(outputStream) output.write(outputStream)
return outputStream.getvalue() return outputStream.getvalue()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment