Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename create_viewer_preference #2167

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ history and [GitHubs 'Contributors' feature](https://github.com/py-pdf/pypdf/gra
* [WevertonGomes](https://github.com/WevertonGomesCosta)
* [Wilson, Huon](https://github.com/huonw)
* ztravis
* [Stober, Marc](https://github.com/marcstober)

## Adding a new contributor

Expand Down
2 changes: 1 addition & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def viewer_preferences(self) -> Optional[ViewerPreferences]:
self._root_object[NameObject(CD.VIEWER_PREFERENCES)] = o
return o

def create_viewer_preference(self) -> ViewerPreferences:
def create_viewer_preferences(self) -> ViewerPreferences:
o = ViewerPreferences()
self._root_object[NameObject(CD.VIEWER_PREFERENCES)] = self._add_object(o)
return o
Expand Down
9 changes: 4 additions & 5 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,10 +1725,7 @@ def test_damaged_pdf_length_returning_none():

@pytest.mark.enable_socket()
def test_viewerpreferences():
"""
Add Tests for ViewerPreferences
https://github.com/py-pdf/pypdf/issues/140#issuecomment-1685380549
"""
"""Add Tests for ViewerPreferences"""
url = "https://github.com/py-pdf/pypdf/files/9175966/2015._pb_decode_pg0.pdf"
name = "2015._pb_decode_pg0.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
Expand Down Expand Up @@ -1779,8 +1776,10 @@ def test_viewerpreferences():
v.print_pagerange = ArrayObject()
assert len(v.print_pagerange) == 0

writer.create_viewer_preference()
writer.create_viewer_preferences()
assert len(writer._root_object["/ViewerPreferences"]) == 0
writer.viewer_preferences.direction = "/R2L"
assert len(writer._root_object["/ViewerPreferences"]) == 1

del reader.trailer["/Root"]["/ViewerPreferences"]
assert reader.viewer_preferences is None
Expand Down