From b38caee37dac6f3439485916573765415d8df88b Mon Sep 17 00:00:00 2001 From: Sebastian Deiss Date: Mon, 5 Mar 2018 11:03:38 +0100 Subject: [PATCH 1/2] Fix TypeError in PDFObjectStream.resolveReferences() A new optional parameter 'parser' was introduced for 'PDFObjectStream', which takes a 'PDFParser' object. This object is then used in 'resolveReferences()' to invoke 'PDFParser.readObject()'. This commit fixes https://github.com/jesparza/peepdf/issues/70. --- peepdf/PDFCore.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/peepdf/PDFCore.py b/peepdf/PDFCore.py index 8e35177..ccd01b4 100644 --- a/peepdf/PDFCore.py +++ b/peepdf/PDFCore.py @@ -2685,7 +2685,8 @@ def setRawStream(self, newStream): class PDFObjectStream (PDFStream): - def __init__(self, rawDict='', rawStream='', elements={}, rawNames={}, compressedObjectsDict={}): + def __init__(self, rawDict='', rawStream='', elements={}, rawNames={}, compressedObjectsDict={}, parser=None): + self.parser = parser self.type = 'stream' self.dictType = '' self.errors = [] @@ -3247,8 +3248,8 @@ def resolveReferences(self): numbers = re.findall('\d{1,10}', offsetsSection) if numbers != [] and len(numbers) % 2 == 0: for i in range(0, len(numbers), 2): - offset = numbers[i+1] - ret = PDFParser.readObject(objectsSection[offset:]) + offset = int(numbers[i + 1]) + ret = self.parser.readObject(objectsSection[offset:]) if ret[0] == -1: if isForceMode: object = None @@ -7417,7 +7418,7 @@ def createPDFStream(self, dict, stream): name = ret[1] if "/Type" in elements and elements['/Type'].getValue() == '/ObjStm': try: - pdfStream = PDFObjectStream(dict, stream, elements, rawNames, {}) + pdfStream = PDFObjectStream(dict, stream, elements, rawNames, {}, parser=self) except Exception as e: errorMessage = 'Error creating PDFObjectStream' if e.message != '': From 11e0c322c6440f3033bb230444e08a98f793e7ca Mon Sep 17 00:00:00 2001 From: Sebastian Deiss Date: Mon, 5 Mar 2018 11:11:18 +0100 Subject: [PATCH 2/2] Added myself to AUTHORS --- AUTHORS | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index c24d744..78fbe53 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,7 @@ Jose Miguel Esparza http://eternal-todo.com -http://twitter.com/EternalTodo \ No newline at end of file +http://twitter.com/EternalTodo + +Sebastian Deiss +https://pages.atos.net/de/sc/ +https://github.com/SebastianDeiss