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

ROB : Cope with null params for FitH /FitV destination #1152

Merged
merged 1 commit into from
Jul 23, 2022
Merged
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
13 changes: 11 additions & 2 deletions PyPDF2/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def writeToStream(
deprecate_with_replacement("writeToStream", "write_to_stream")
self.write_to_stream(stream, encryption_key)

def __repr__(self) -> str:
return "NullObject"

@staticmethod
def readFromStream(stream: StreamType) -> "NullObject": # pragma: no cover
deprecate_with_replacement("readFromStream", "read_from_stream")
Expand Down Expand Up @@ -1813,9 +1816,15 @@ def __init__(
self[NameObject(TA.TOP)],
) = args
elif typ in [TF.FIT_H, TF.FIT_BH]:
(self[NameObject(TA.TOP)],) = args
try: # Prefered to be more robust not only to null parameters
(self[NameObject(TA.TOP)],) = args
except Exception:
(self[NameObject(TA.TOP)],) = (NullObject(),)
elif typ in [TF.FIT_V, TF.FIT_BV]:
(self[NameObject(TA.LEFT)],) = args
try: # Prefered to be more robust not only to null parameters
(self[NameObject(TA.LEFT)],) = args
except Exception:
(self[NameObject(TA.LEFT)],) = (NullObject(),)
elif typ in [TF.FIT, TF.FIT_B]:
pass
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,11 @@ def test_sweep_indirect_list_newobj_is_None():

# cleanup
os.remove("tmp-merger-do-not-commit.pdf")


def test_iss1145():
# issue with FitH destination with null param
url = "https://github.com/py-pdf/PyPDF2/files/9164743/file-0.pdf"
name = "iss1145.pdf"
merger = PdfMerger()
merger.append(PdfReader(BytesIO(get_pdf_from_url(url, name=name))))