Skip to content

Commit

Permalink
Various smaller places
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Dec 24, 2023
1 parent 3b64cb4 commit 8263e1e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
32 changes: 32 additions & 0 deletions pypdf/_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,38 @@ def set_page_mode(self, mode: PagemodeType) -> None:
* - /UseAttachments
- Show attachments panel
"""
self.page_mode = mode

Check warning on line 380 in pypdf/_merger.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_merger.py#L380

Added line #L380 was not covered by tests

@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

Check warning on line 408 in pypdf/_merger.py

View check run for this annotation

Codecov / codecov/patch

pypdf/_merger.py#L408

Added line #L408 was not covered by tests

@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
Expand Down
2 changes: 1 addition & 1 deletion tests/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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)


Expand Down
16 changes: 5 additions & 11 deletions tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8263e1e

Please sign in to comment.