Commits (5)
......@@ -74,7 +74,7 @@ Build-Depends:
python3-magic,
python3-pdfminer <!nocheck>,
python3-progressbar <!nocheck>,
python3-pypdf2 <!nocheck>,
python3-pypdf <!nocheck>,
python3-pytest <!nocheck>,
python3-pytest-cov <!nocheck>,
python3-pyxattr <!nocheck>,
......
......@@ -37,9 +37,12 @@ try:
try:
import pypdf
except ImportError:
import PyPDF2
import PyPDF2 as pypdf
pypdf = PyPDF2
try:
import pypdf.PdfReader as PdfReader
except ImportError:
import pypdf.PdfFileReader as PdfReader
try:
from pypdf.errors import PdfReadError
......@@ -83,8 +86,8 @@ class PdfFile(File):
)
else:
difference = Difference.from_text(
self.dump_pypdf2_metadata(self),
self.dump_pypdf2_metadata(other),
self.dump_pypdf_metadata(self),
self.dump_pypdf_metadata(other),
self.name,
other.name,
)
......@@ -93,8 +96,8 @@ class PdfFile(File):
xs.append(difference)
difference = Difference.from_text(
self.dump_pypdf2_annotations(self),
self.dump_pypdf2_annotations(other),
self.dump_pypdf_annotations(self),
self.dump_pypdf_annotations(other),
self.name,
other.name,
)
......@@ -113,7 +116,7 @@ class PdfFile(File):
return xs
def dump_pypdf2_metadata(self, file):
def dump_pypdf_metadata(self, file):
try:
pdf = pypdf.PdfReader(file.path)
document_info = pdf.metadata
......@@ -132,7 +135,10 @@ class PdfFile(File):
logger.error(msg)
return ""
def dump_pypdf2_annotations(self, file):
# for backward compatibility:
dump_pypdf2_metadata = dump_pypdf_metadata
def dump_pypdf_annotations(self, file):
try:
pdf = pypdf.PdfReader(file.path)
......@@ -154,3 +160,6 @@ class PdfFile(File):
file.add_comment(msg)
logger.error(msg)
return ""
# for backward compatibility:
dump_pypdf2_annotations = dump_pypdf_annotations
......@@ -183,7 +183,7 @@ EXTERNAL_TOOLS = {
"FreeBSD": "ghostscript9-base",
"guix": "ghostscript",
},
"pypdf2": {"debian": "python3-pypdf2"},
"pypdf": {"debian": "python3-pypdf"},
"radare2": {"debian": "radare2", "arch": "radare2", "guix": "radare2"},
"readelf": {
"debian": "binutils-multiarch",
......
......@@ -83,6 +83,4 @@ def differences_annotations(pdf3, pdf4):
@skip_unless_tools_exist("pdftotext")
@skip_unless_module_exists("pypdf")
def test_annotations(differences_annotations):
with open("tests/data/pdf_annotations_expected_diff", "w") as f:
f.write(differences_annotations[0].unified_diff)
assert_diff(differences_annotations[0], "pdf_annotations_expected_diff")
@@ -0,0 +1,2 @@
+1: A PDF comment created in Okular
+11: Comment created with evince
@@ -1,3 +1,7 @@
This is a test PDF.
+10: Typewriter annotation
+2: Another type of
+comment
+