Skip to content
Snippets Groups Projects
Commit 3adcd3bd authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Support both PyPDF 1.x and 2.x.

parent da5458ee
No related branches found
No related tags found
No related merge requests found
Pipeline #385140 passed
......@@ -27,6 +27,14 @@ from .utils.command import Command
try:
import PyPDF2
try:
# PyPDF 2.x
from PyPDF2.errors import PdfReadError
except ImportError:
# PyPDF 1.x
from PyPDF2.utils import PdfReadError
except ImportError: # noqa
python_module_missing("PyPDF2")
PyPDF2 = None
......@@ -92,7 +100,7 @@ class PdfFile(File):
try:
pdf = PyPDF2.PdfFileReader(file.path)
document_info = pdf.getDocumentInfo()
except PyPDF2.utils.PdfReadError as e:
except PdfReadError as e:
return f"(Could not extract metadata: {e})"
if document_info is None:
......@@ -108,7 +116,7 @@ class PdfFile(File):
def dump_pypdf2_annotations(file):
try:
pdf = PyPDF2.PdfFileReader(file.path)
except PyPDF2.utils.PdfReadError as e:
except PdfReadError as e:
return f"(Could not open file: {e})"
xs = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment