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,6 +41,7 @@ def mergePDFList(self, pdf_data_list, start_on_recto=False): ...@@ -41,6 +41,7 @@ def mergePDFList(self, pdf_data_list, start_on_recto=False):
output = PdfFileWriter() output = PdfFileWriter()
for pdf_data in pdf_data_list: for pdf_data in pdf_data_list:
if pdf_data:
pdf_reader = PdfFileReader(StringIO(pdf_data)) pdf_reader = PdfFileReader(StringIO(pdf_data))
page_count = pdf_reader.getNumPages() page_count = pdf_reader.getNumPages()
for page in range(page_count): for page in range(page_count):
......
1 2
\ No newline at end of file \ No newline at end of file
...@@ -83,6 +83,10 @@ class PDFDocument(Image): ...@@ -83,6 +83,10 @@ class PDFDocument(Image):
index is 0 based) index is 0 based)
""" """
from pyPdf import PdfFileWriter, PdfFileReader, pdf 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())) self_reader = PdfFileReader(StringIO(self.getData()))
watermark_reader = PdfFileReader(StringIO(watermark_data)) watermark_reader = PdfFileReader(StringIO(watermark_data))
watermark_page_count = watermark_reader.getNumPages() 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