diff --git a/pypdf/_utils.py b/pypdf/_utils.py index 20d14c387..df652d4d7 100644 --- a/pypdf/_utils.py +++ b/pypdf/_utils.py @@ -202,11 +202,7 @@ def check_if_whitespace_only(value: bytes) -> bool: True if the value only has whitespace characters, otherwise return False. """ - for index in range(len(value)): - current = value[index : index + 1] - if current not in WHITESPACES: - return False - return True + return all(b in WHITESPACES_AS_BYTES for b in value) def skip_over_comment(stream: StreamType) -> None: