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

Do not create PdfFileReader with empty data

pyPdf goes in an infinite loop when PdfFileReader are created on an empty file.
parent 3e2ab836
......@@ -41,13 +41,14 @@ def mergePDFList(self, pdf_data_list, start_on_recto=False):
output = PdfFileWriter()
for pdf_data in pdf_data_list:
pdf_reader = PdfFileReader(StringIO(pdf_data))
page_count = pdf_reader.getNumPages()
for page in range(page_count):
output.addPage(pdf_reader.getPage(page))
if start_on_recto and page_count % 2:
output.addBlankPage()
if pdf_data:
pdf_reader = PdfFileReader(StringIO(pdf_data))
page_count = pdf_reader.getNumPages()
for page in range(page_count):
output.addPage(pdf_reader.getPage(page))
if start_on_recto and page_count % 2:
output.addBlankPage()
outputStream = StringIO()
output.write(outputStream)
return outputStream.getvalue()
1
\ No newline at end of file
2
\ No newline at end of file
......@@ -83,6 +83,10 @@ class PDFDocument(Image):
index is 0 based)
"""
from pyPdf import PdfFileWriter, PdfFileReader, pdf
if not watermark_data:
raise ValueError("watermark_data cannot not be empty")
if not self.hasData():
raise ValueError("Cannot watermark an empty document")
self_reader = PdfFileReader(StringIO(self.getData()))
watermark_reader = PdfFileReader(StringIO(watermark_data))
watermark_page_count = watermark_reader.getNumPages()
......
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