mergePage crash pypdf

Bug #528329 reported by Pier Carteri
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyPdf
Confirmed
Undecided
Unassigned

Bug Description

Platform: Windows XP sp3
Python: 2.6.3
PyPdf: last official release 1.12 / same problem with last git

I'm trying to merge 2 page of different pdf into one with the following code:

from pyPdf import PdfFileWriter, PdfFileReader

#input file 1
in_1 = PdfFileReader(file("in_1.pdf", "rb"))

#input file 2
in_2 = PdfFileReader(file("in_2.pdf", "rb"))

page_1 = in_1.getPage(0)
page_1.mergePage(in_2.getPage(0))

output.addPage(page_1)
outputStream = file("out_2.pdf", "wb")
output.write(outputStream)
outputStream.close()

and i get this error

Traceback (most recent call last):
  File "merge_test.py", line 11, in <module>
    page_1.mergePage(in_2.getPage(0))
  File "c:\Python26\lib\site-packages\pyPdf\pdf.py", line 1102, in mergePage
    self._mergePage(page2)
  File "c:\Python26\lib\site-packages\pyPdf\pdf.py", line 1146, in _mergePage
    originalContent, self.pdf))
  File "c:\Python26\lib\site-packages\pyPdf\pdf.py", line 1065, in _pushPopGS
    stream = ContentStream(contents, pdf)
  File "c:\Python26\lib\site-packages\pyPdf\pdf.py", line 1440, in __init__
    self.__parseContentStream(stream)
  File "c:\Python26\lib\site-packages\pyPdf\pdf.py", line 1479, in __parseContentStream
    operands.append(readObject(stream, None))
  File "c:\Python26\lib\site-packages\pyPdf\generic.py", line 87, in readObject
    return NumberObject.readFromStream(stream)
  File "c:\Python26\lib\site-packages\pyPdf\generic.py", line 236, in readFromStream
    return NumberObject(name)
ValueError: invalid literal for int() with base 10: ''

Let me know if you need also the pdf I've used.
Thank you!

Revision history for this message
Pier Carteri (pier-carteri) wrote :
Revision history for this message
Pier Carteri (pier-carteri) wrote :

I' ve checked that this problem is related to the pdfs I'm using, because with other pdfs there is no crash.
I change the bug status to invalid.
Thanks!

Changed in pypdf:
status: New → Invalid
Revision history for this message
Olivier (oc-spam66) wrote :

I don't get why this isn't a bug.

Changed in pypdf:
status: Invalid → New
Revision history for this message
Olivier (oc-spam66) wrote :

I have the same bug.

Changed in pypdf:
status: New → Confirmed
Revision history for this message
Olivier (oc-spam66) wrote :

I can merge on the first page of this file, but not on the second.
The error is:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

     84 print "Page: " + str(n)
     85 page = base_pdf.getPage(n)
---> 86 page.mergePage(stamp_page)
     87 output.addPage(page)
     88

/usr/lib/pymodules/python2.6/pyPdf/pdf.pyc in mergePage(self, page2)
    995
    996 originalContent = self["/Contents"].getObject()
--> 997 newContentArray.append(PageObject._pushPopGS(originalContent, self.pdf))
    998
    999 page2Content = page2['/Contents'].getObject()

/usr/lib/pymodules/python2.6/pyPdf/pdf.pyc in _pushPopGS(contents, pdf)
    952 # of a content stream. This isolates it from changes such as

    953 # transformation matricies.

--> 954 stream = ContentStream(contents, pdf)
    955 stream.operations.insert(0, [[], "q"])
    956 stream.operations.append([[], "Q"])

/usr/lib/pymodules/python2.6/pyPdf/pdf.pyc in __init__(self, stream, pdf)
   1116 else:
   1117 stream = StringIO(stream.getData())
-> 1118 self.__parseContentStream(stream)
   1119
   1120 def __parseContentStream(self, stream):

/usr/lib/pymodules/python2.6/pyPdf/pdf.pyc in __parseContentStream(self, stream)
   1155 peek = stream.read(1)
   1156 else:
-> 1157 operands.append(readObject(stream, None))
   1158
   1159 def _readInlineImage(self, stream):

/usr/lib/pymodules/python2.6/pyPdf/generic.pyc in readObject(stream, pdf)
     85 return IndirectObject.readFromStream(stream, pdf)
     86 else:
---> 87 return NumberObject.readFromStream(stream)
     88
     89 class PdfObject(object):

/usr/lib/pymodules/python2.6/pyPdf/generic.pyc in readFromStream(stream)
    230 return FloatObject(name)
    231 else:
--> 232 return NumberObject(name)
    233 readFromStream = staticmethod(readFromStream)
    234

ValueError: invalid literal for int() with base 10: ''
------------------------------------------------------------------------------------------------------------

Revision history for this message
Olivier (oc-spam66) wrote :

The file I use for the merge is given here.

Best regards,

O.C.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.