Skip to content

Commit

Permalink
fix: support PyPDF2 >=2.0
Browse files Browse the repository at this point in the history
Early versions of PyPDF2 1.x no longer supported.

Addresses #13.
  • Loading branch information
michaelmhoffman committed Jun 2, 2023
1 parent 25270a1 commit 32decc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions pdfcomments/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import sys
from typing import DefaultDict, Iterator, List, Optional, TextIO

from PyPDF2 import PdfFileReader
from PyPDF2.pdf import PageObject
from PyPDF2 import PageObject, PdfReader

try:
from os import EX_OK
Expand Down Expand Up @@ -43,13 +42,12 @@


def iter_annot_contents(page: PageObject) -> Iterator[str]:
try:
annot_indirects = page["/Annots"]
except KeyError:
annot_indirects = page.annotations
if annot_indirects is None:
return

for annot_indirect in annot_indirects:
annot = annot_indirect.getObject()
annot = annot_indirect.get_object()

try:
yield annot["/Contents"]
Expand All @@ -60,7 +58,7 @@ def iter_annot_contents(page: PageObject) -> Iterator[str]:
def load_comments(filename: str) -> SeverityDict:
res: SeverityDict = defaultdict(list)

reader = PdfFileReader(filename, STRICT)
reader = PdfReader(filename, STRICT)

# In enumerate(reader.pages, 1), the 1 makes pages printed 1-based instead
# of 0-based, as is used by all user-facing PDF software
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
license='GPLv3',
package_data={"pdfcomments": ["py.typed"]},
packages=['pdfcomments'],
install_requires=['PyPDF2'],
install_requires=['PyPDF2>=1.28'],
python_requires='>=3.6',
entry_points={
'console_scripts': ['pdfcomments=pdfcomments.__main__:main'],
Expand Down

0 comments on commit 32decc0

Please sign in to comment.