diff --git a/pypdf/_merger.py b/pypdf/_merger.py index 7dca9c90a..8758dbec0 100644 --- a/pypdf/_merger.py +++ b/pypdf/_merger.py @@ -377,6 +377,38 @@ def set_page_mode(self, mode: PagemodeType) -> None: * - /UseAttachments - Show attachments panel """ + self.page_mode = mode + + @property + def page_mode(self) -> Optional[PagemodeType]: + """ + Set the page mode. + + Args: + mode: The page mode to use. + + .. list-table:: Valid ``mode`` arguments + :widths: 50 200 + + * - /UseNone + - Do not show outline or thumbnails panels + * - /UseOutlines + - Show outline (aka bookmarks) panel + * - /UseThumbs + - Show page thumbnails panel + * - /FullScreen + - Fullscreen view + * - /UseOC + - Show Optional Content Group (OCG) panel + * - /UseAttachments + - Show attachments panel + """ + if self.output is None: + raise RuntimeError(ERR_CLOSED_WRITER) + return self.output.page_mode + + @page_mode.setter + def page_mode(self, mode: PagemodeType) -> None: if self.output is None: raise RuntimeError(ERR_CLOSED_WRITER) self.output.page_mode = mode diff --git a/tests/bench.py b/tests/bench.py index 7c91406ef..67625193a 100644 --- a/tests/bench.py +++ b/tests/bench.py @@ -96,7 +96,7 @@ def merge(): writer.add_metadata({"author": "Martin Thoma"}) writer.add_named_destination("title", 0) writer.set_page_layout("/SinglePage") - writer.set_page_mode("/UseThumbs") + writer.page_mode = "/UseThumbs" write_path = "dont_commit_merged.pdf" writer.write(write_path) diff --git a/tests/test_merger.py b/tests/test_merger.py index 9b4296175..3d7917902 100644 --- a/tests/test_merger.py +++ b/tests/test_merger.py @@ -130,7 +130,7 @@ def merger_operate(merger): merger.add_metadata({"/Author": "Martin Thoma"}) merger.add_named_destination("/Title", 0) merger.set_page_layout("/SinglePage") - merger.set_page_mode("/UseThumbs") + merger.page_mode = "/UseThumbs" def check_outline(tmp_path): @@ -288,7 +288,7 @@ def test_merge_write_closed_fh(): assert exc.value.args[0] == err_closed with pytest.raises(RuntimeError) as exc: - merger.set_page_mode("/UseNone") + merger.page_mode = "/UseNone" assert exc.value.args[0] == err_closed with pytest.raises(RuntimeError) as exc: @@ -313,7 +313,7 @@ def test_merge_write_closed_fh_with_writer(pdf_file_path): merger.write(pdf_file_path) merger.add_metadata({"author": "Martin Thoma"}) merger.set_page_layout("/SinglePage") - merger.set_page_mode("/UseNone") + merger.page_mode = "/UseNone" merger.add_outline_item("An outline item", 0) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index de43fe7a8..6cc0fe750 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -268,20 +268,14 @@ def test_extract_textbench(enable, url, pages, print_result=False): @pytest.mark.slow() def test_orientations(): p = PdfReader(RESOURCE_ROOT / "test Orient.pdf").pages[0] - with pytest.warns(DeprecationWarning): - p.extract_text("", "") - with pytest.warns(DeprecationWarning): - p.extract_text("", "", 0) - with pytest.warns(DeprecationWarning): - p.extract_text("", "", 0, 200) - - with pytest.warns(DeprecationWarning): - p.extract_text(Tj_sep="", TJ_sep="") + p.extract_text("", "") + p.extract_text("", "", 0) + p.extract_text("", "", 0, 200) + p.extract_text() assert findall("\\((.)\\)", p.extract_text()) == ["T", "B", "L", "R"] with pytest.raises(Exception): p.extract_text(None) - with pytest.raises(Exception): - p.extract_text("", 0) + p.extract_text("", 0) with pytest.raises(Exception): p.extract_text("", "", None) with pytest.raises(Exception): diff --git a/tests/test_writer.py b/tests/test_writer.py index 93446d59b..1cae9fde9 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -191,9 +191,9 @@ def writer_operate(writer: PdfWriter) -> None: writer.page_layout = NameObject("/SinglePage") assert writer._get_page_layout() == "/SinglePage" assert writer._get_page_mode() is None - writer.set_page_mode("/UseNone") + writer.page_mode = "/UseNone" assert writer._get_page_mode() == "/UseNone" - writer.set_page_mode(NameObject("/UseOC")) + writer.page_mode = NameObject("/UseOC") assert writer._get_page_mode() == "/UseOC" writer.insert_blank_page(width=100, height=100) writer.insert_blank_page() # without parameters