diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index 422b53319..826f73369 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -1422,11 +1422,13 @@ def getPage(self, pageNumber): self._flatten() return self.flattenedPages[pageNumber] - namedDestinations = property(lambda self: self.getNamedDestinations(), None, None) - """ - Read-only property that accesses the - :meth:`getNamedDestinations()` function. - """ + @property + def namedDestinations(self): + """ + Read-only property that accesses the + :meth:`getNamedDestinations()` function. + """ + return self.getNamedDestinations() # A select group of relevant field attributes. For the complete list, # see section 8.6.2 of the PDF 1.7 reference. diff --git a/Scripts/2-up.py b/Scripts/2-up.py index 2540e0114..26dd90e2f 100644 --- a/Scripts/2-up.py +++ b/Scripts/2-up.py @@ -18,7 +18,7 @@ def main(): print("2-up input " + sys.argv[1]) reader = PdfFileReader(sys.argv[1]) writer = PdfFileWriter() - for iter in range(0, reader.getNumPages() - 1, 2): + for iter in range(0, reader.numPages - 1, 2): lhs = reader.getPage(iter) rhs = reader.getPage(iter + 1) lhs.mergeTranslatedPage(rhs, lhs.mediaBox.getUpperRight_x(), 0, True) diff --git a/Scripts/booklet.py b/Scripts/booklet.py index f074bd7cd..80a25917e 100644 --- a/Scripts/booklet.py +++ b/Scripts/booklet.py @@ -23,7 +23,7 @@ def main(): args = parser.parse_args() reader = PyPDF2.PdfFileReader(args.input) - numPages = reader.getNumPages() + numPages = reader.numPages print("Pages in file:", numPages) pagesPerSheet = 4 diff --git a/Tests/test_basic_features.py b/Tests/test_basic_features.py index 1d4fa7d28..7504772bb 100644 --- a/Tests/test_basic_features.py +++ b/Tests/test_basic_features.py @@ -16,7 +16,7 @@ def test_basic_features(): reader = PdfFileReader(pdf_path) writer = PdfFileWriter() - reader.getNumPages() + assert reader.numPages == 1 # add page 1 from input1 to output document, unchanged writer.addPage(reader.getPage(0)) diff --git a/Tests/test_reader.py b/Tests/test_reader.py index dcef0f471..00bc81c73 100644 --- a/Tests/test_reader.py +++ b/Tests/test_reader.py @@ -32,7 +32,7 @@ def test_get_num_pages(src, num_pages): src = os.path.join(RESOURCE_ROOT, src) reader = PdfFileReader(src) - assert reader.getNumPages() == num_pages + assert reader.numPages == num_pages @pytest.mark.parametrize( @@ -71,7 +71,7 @@ def test_get_num_pages(src, num_pages): def test_read_metadata(pdf_path, expected): with open(pdf_path, "rb") as inputfile: reader = PdfFileReader(inputfile) - docinfo = reader.getDocumentInfo() + docinfo = reader.documentInfo metadict = dict(docinfo) assert metadict == expected docinfo.title @@ -117,7 +117,7 @@ def test_get_attachments(src): reader = PdfFileReader(src) attachments = {} - for i in range(reader.getNumPages()): + for i in range(reader.numPages): page = reader.getPage(i) if PG.ANNOTS in page: for annotation in page[PG.ANNOTS]: @@ -485,12 +485,12 @@ def test_read_unknown_zero_pages(): pdf_stream = io.BytesIO(pdf_data) with pytest.raises(PdfReadError) as exc: reader = PdfFileReader(pdf_stream, strict=True) - reader.getNumPages() + reader.numPages assert exc.value.args[0] == "Could not find object." reader = PdfFileReader(pdf_stream, strict=False) with pytest.raises(AttributeError) as exc: - reader.getNumPages() + reader.numPages assert exc.value.args[0] == "'NoneType' object has no attribute 'getObject'" @@ -498,7 +498,7 @@ def test_read_encrypted_without_decryption(): src = os.path.join(RESOURCE_ROOT, "libreoffice-writer-password.pdf") reader = PdfFileReader(src) with pytest.raises(PdfReadError) as exc: - reader.getNumPages() + reader.numPages assert exc.value.args[0] == "File has not been decrypted" diff --git a/Tests/test_writer.py b/Tests/test_writer.py index e2ef5cdb0..4e8013b1f 100644 --- a/Tests/test_writer.py +++ b/Tests/test_writer.py @@ -343,7 +343,7 @@ def test_io_streams(): # Read from bytes stream reader = PdfFileReader(bytes_stream) - assert reader.getNumPages() == 4 + assert reader.numPages == 4 # Write to bytes stream writer = PdfFileWriter() diff --git a/Tests/test_xmp.py b/Tests/test_xmp.py index a477717a6..e0aed7900 100644 --- a/Tests/test_xmp.py +++ b/Tests/test_xmp.py @@ -19,7 +19,7 @@ ) def test_read_xmp(src, has_xmp): reader = PdfFileReader(src) - xmp = reader.getXmpMetadata() + xmp = reader.xmpMetadata assert (xmp is None) == (not has_xmp) if has_xmp: for el in xmp.getElement(