Skip to content

Commit

Permalink
STY: Tiny refactor (#2901)
Browse files Browse the repository at this point in the history
Functions insert_blank_page and _pdf_objectify.
  • Loading branch information
j-t-1 authored Oct 14, 2024
1 parent c9dda9a commit f5c3cf2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def insert_blank_page(
PageSizeNotDefinedError: if width and height are not defined
and previous page does not exist.
"""
if width is None or height is None and (self.get_num_pages() - 1) >= index:
if width is None or height is None and index < self.get_num_pages():
oldpage = self.pages[index]
width = oldpage.mediabox.width
height = oldpage.mediabox.height
Expand Down Expand Up @@ -3244,18 +3244,18 @@ def _pdf_objectify(obj: Union[Dict[str, Any], str, int, List[Any]]) -> PdfObject
casted_value = _pdf_objectify(value)
to_add[name_key] = casted_value
return to_add
elif isinstance(obj, list):
return ArrayObject(_pdf_objectify(el) for el in obj)
elif isinstance(obj, str):
if obj.startswith("/"):
return NameObject(obj)
else:
return TextStringObject(obj)
elif isinstance(obj, (int, float)):
return FloatObject(obj)
elif isinstance(obj, list):
return ArrayObject(_pdf_objectify(i) for i in obj)
else:
raise NotImplementedError(
f"type(obj)={type(obj)} could not be casted to PdfObject"
f"{type(obj)=} could not be cast to a PdfObject"
)


Expand Down

0 comments on commit f5c3cf2

Please sign in to comment.