diff --git a/docs/user/forms.md b/docs/user/forms.md index 5e8107390..40ea1606a 100644 --- a/docs/user/forms.md +++ b/docs/user/forms.md @@ -48,6 +48,7 @@ The PDF form stores form fields as annotations with the subtype "\Widget". This ```python from pypdf import PdfReader + reader = PdfReader("form.pdf") fields = reader.get_fields() ``` @@ -55,6 +56,7 @@ fields = reader.get_fields() ```python from pypdf import PdfReader from pypdf.constants import AnnotationDictionaryAttributes + reader = PdfReader("form.pdf") fields = [] for page in reader.pages: diff --git a/pypdf/_text_extraction/__init__.py b/pypdf/_text_extraction/__init__.py index 37af3cd54..8a024719b 100644 --- a/pypdf/_text_extraction/__init__.py +++ b/pypdf/_text_extraction/__init__.py @@ -214,7 +214,6 @@ def handle_tj( rtl_dir: bool, visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]], ) -> Tuple[str, bool]: - m = mult(tm_matrix, cm_matrix) orientation = orient(m) if orientation in orientations and len(operands) > 0: diff --git a/pypdf/_xobj_image_helpers.py b/pypdf/_xobj_image_helpers.py index 1c41c453b..9041d7737 100644 --- a/pypdf/_xobj_image_helpers.py +++ b/pypdf/_xobj_image_helpers.py @@ -198,9 +198,13 @@ def bits2byte(data: bytes, size: Tuple[int, int], bits: int) -> bytes: expected_count = 2 * nb if len(lookup) != expected_count: if len(lookup) < expected_count: - raise PdfReadError(f"Not enough lookup values: Expected {expected_count}, got {len(lookup)}.") + raise PdfReadError( + f"Not enough lookup values: Expected {expected_count}, got {len(lookup)}." + ) if not check_if_whitespace_only(lookup[expected_count:]): - raise PdfReadError(f"Too many lookup values: Expected {expected_count}, got {len(lookup)}.") + raise PdfReadError( + f"Too many lookup values: Expected {expected_count}, got {len(lookup)}." + ) lookup = lookup[:expected_count] colors_arr = [lookup[:nb], lookup[nb:]] arr = b"".join( diff --git a/tests/test_xobject_image_helpers.py b/tests/test_xobject_image_helpers.py index 0e515cae5..63ecebd9b 100644 --- a/tests/test_xobject_image_helpers.py +++ b/tests/test_xobject_image_helpers.py @@ -33,9 +33,15 @@ def test_handle_flate__image_mode_1(): data = b"\x00\xe0\x00" lookup = DecodedStreamObject() expected_data = [ - (66, 66, 66), (66, 66, 66), (66, 66, 66), - (0, 19, 55), (0, 19, 55), (0, 19, 55), - (66, 66, 66), (66, 66, 66), (66, 66, 66) + (66, 66, 66), + (66, 66, 66), + (66, 66, 66), + (0, 19, 55), + (0, 19, 55), + (0, 19, 55), + (66, 66, 66), + (66, 66, 66), + (66, 66, 66), ] # No trailing data. @@ -44,9 +50,11 @@ def test_handle_flate__image_mode_1(): size=(3, 3), data=data, mode="1", - color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]), + color_space=ArrayObject( + [NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup] + ), colors=2, - obj_as_text="dummy" + obj_as_text="dummy", ) assert expected_data == list(result[0].getdata()) @@ -56,32 +64,52 @@ def test_handle_flate__image_mode_1(): size=(3, 3), data=data, mode="1", - color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]), + color_space=ArrayObject( + [NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup] + ), colors=2, - obj_as_text="dummy" + obj_as_text="dummy", ) assert expected_data == list(result[0].getdata()) # Trailing non-whitespace character. lookup.set_data(b"\x42\x42\x42\x00\x13\x37\x12") - with pytest.raises(PdfReadError, match=r"^Too many lookup values: Expected 6, got 7\.$"): + with pytest.raises( + PdfReadError, match=r"^Too many lookup values: Expected 6, got 7\.$" + ): _handle_flate( size=(3, 3), data=data, mode="1", - color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]), + color_space=ArrayObject( + [ + NameObject("/Indexed"), + NameObject("/DeviceRGB"), + NumberObject(1), + lookup, + ] + ), colors=2, - obj_as_text="dummy" + obj_as_text="dummy", ) # Not enough lookup data. lookup.set_data(b"\x42\x42\x42\x00\x13") - with pytest.raises(PdfReadError, match=r"^Not enough lookup values: Expected 6, got 5\.$"): + with pytest.raises( + PdfReadError, match=r"^Not enough lookup values: Expected 6, got 5\.$" + ): _handle_flate( size=(3, 3), data=data, mode="1", - color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]), + color_space=ArrayObject( + [ + NameObject("/Indexed"), + NameObject("/DeviceRGB"), + NumberObject(1), + lookup, + ] + ), colors=2, - obj_as_text="dummy" + obj_as_text="dummy", )