Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Update walkpdf to fix PyPDF deprecation warnings #934

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions xml2rfc/walkpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def walk(obj, seen):
d, i = walk(obj[key], seen)
dobj[k] = d
iobj += i
if hasattr(obj, 'extractText'):
dobj['text'] = obj.extractText()
if hasattr(obj, 'extract_text'):
dobj['text'] = obj.extract_text()
elif isinstance(obj, pypdf2.generic.ArrayObject):
dobj = []
for o in obj:
Expand All @@ -41,7 +41,7 @@ def walk(obj, seen):
dobj = str(obj)
if (obj.idnum, obj.generation) not in seen:
seen.add((obj.idnum, obj.generation))
d, i = walk(obj.getObject(), seen)
d, i = walk(obj.get_object(), seen)
if isinstance(d, dict):
d['IdNum'] = obj.idnum
d['Generation'] = obj.generation
Expand All @@ -63,17 +63,17 @@ def pyobj(filename=None, bytes=None):
seen = set()
#
pdffile = io.BytesIO(bytes) if bytes else io.open(filename, 'br')
reader = pypdf2.PdfFileReader(pdffile, strict=False)
info = reader.getDocumentInfo()
reader = pypdf2.PdfReader(pdffile, strict=False)
info = reader.metadata
doc = {}
for key in info.keys():
k = key[1:] if key.startswith('/') else key
doc[k] = info[key]
iobj = []
pages = []
for num in range(reader.getNumPages()):
page = reader.getPage(num)
obj = page.getObject()
for num in range(len(reader.pages)):
page = reader.pages[num]
obj = page.get_object()
d, i = walk(obj, seen)
#pages[num+1] = d
pages.append(d)
Expand Down Expand Up @@ -110,4 +110,4 @@ def main():
print('Wrote: %s' % x.name)

if __name__ == "__main__":
main()
main()