diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 463bc2988..1d9e84a38 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -2194,29 +2194,19 @@ def remove_images( Remove images from this output. Args: - to_delete : The type of images to be deleted + to_delete: The type of images to be deleted (default = all images types) """ if isinstance(to_delete, bool): to_delete = ImageType.ALL - i = ( - ( - ObjectDeletionFlag.XOBJECT_IMAGES - if to_delete & ImageType.XOBJECT_IMAGES - else ObjectDeletionFlag.NONE - ) - | ( - ObjectDeletionFlag.INLINE_IMAGES - if to_delete & ImageType.INLINE_IMAGES - else ObjectDeletionFlag.NONE - ) - | ( - ObjectDeletionFlag.DRAWING_IMAGES - if to_delete & ImageType.DRAWING_IMAGES - else ObjectDeletionFlag.NONE - ) - ) + + i = ObjectDeletionFlag.NONE + + for image in ("XOBJECT_IMAGES", "INLINE_IMAGES", "DRAWING_IMAGES"): + if to_delete & ImageType[image]: + i |= ObjectDeletionFlag[image] + for page in self.pages: self.remove_objects_from_page(page, i)