diff --git a/src/pypdfium2/_cli/extract_images.py b/src/pypdfium2/_cli/extract_images.py index 53da5fd6f..d47d95e83 100644 --- a/src/pypdfium2/_cli/extract_images.py +++ b/src/pypdfium2/_cli/extract_images.py @@ -87,3 +87,4 @@ def main(args): except pdfium.PdfiumError: traceback.print_exc() image.close() + logger.debug() # newline diff --git a/src/pypdfium2/_helpers/pageobjects.py b/src/pypdfium2/_helpers/pageobjects.py index 0b9a24cef..1e67983ef 100644 --- a/src/pypdfium2/_helpers/pageobjects.py +++ b/src/pypdfium2/_helpers/pageobjects.py @@ -325,7 +325,7 @@ def get_bitmap(self, render=False, scale_to_original=True): bitmap = PdfBitmap.from_raw(raw_bitmap) if render and scale_to_original: - logger.debug(f"Extracted size: {bitmap.width}, {bitmap.height}\n") + logger.debug(f"Extracted size: {bitmap.width}, {bitmap.height}") return bitmap diff --git a/tests/test_pageobjects.py b/tests/test_pageobjects.py index fae39a16c..866ae729c 100644 --- a/tests/test_pageobjects.py +++ b/tests/test_pageobjects.py @@ -191,9 +191,10 @@ def test_replace_image_with_jpeg(): @pytest.mark.parametrize( - "render", [False, True] + "render, scale_to_original", + [(False, None), (True, False), (True, True)] ) -def test_image_get_bitmap(render): +def test_image_get_bitmap(render, scale_to_original): pdf = pdfium.PdfDocument(TestFiles.images) page = pdf[0] @@ -210,25 +211,24 @@ def test_image_get_bitmap(render): assert metadata.marked_content_id == 1 assert metadata.bits_per_pixel == 1 - bitmap = image.get_bitmap(render=render) + bitmap = image.get_bitmap(render=render, scale_to_original=scale_to_original) assert isinstance(bitmap, pdfium.PdfBitmap) if render: assert bitmap.format == pdfium_c.FPDFBitmap_BGRA assert bitmap.n_channels == 4 # Somewhere between pdfium 6462 and 6899, size/stride expectation changed here - assert bitmap.width == 217 - assert bitmap.height == 91 - assert bitmap.stride == 868 + if scale_to_original: + assert (bitmap.width, bitmap.height, bitmap.stride) == (115, 49, 460) + else: + assert (bitmap.width, bitmap.height, bitmap.stride) == (217, 91, 868) assert bitmap.rev_byteorder is False output_path = OutputDir / "extract_rendered.png" else: # NOTE fails with pdfium >= 1e1e173 (6015), < b5bc2e9 (6029), which returns RGB assert bitmap.format == pdfium_c.FPDFBitmap_Gray assert bitmap.n_channels == 1 - assert bitmap.width == 115 - assert bitmap.height == 48 - assert bitmap.stride == 116 + assert (bitmap.width, bitmap.height, bitmap.stride) == (115, 48, 116) assert bitmap.rev_byteorder is False output_path = OutputDir / "extract.png" diff --git a/tests/test_textpage.py b/tests/test_textpage.py index 60789d8a3..9119f27eb 100644 --- a/tests/test_textpage.py +++ b/tests/test_textpage.py @@ -156,22 +156,22 @@ def test_get_text_bounded_defaults_with_rotation(): assert len(text) == 438 -@pytest.mark.parametrize("explicit_close", [False, True]) -def test_autoclose_with_remove_obj(caplog, explicit_close): - - pdf = pdfium.PdfDocument(TestFiles.text) - page = pdf[0] - textobj = next( page.get_objects(filter=[pdfium_c.FPDF_PAGEOBJ_TEXT]) ) - assert len(page._kids) == 0 - textpage = page.get_textpage() - assert len(page._kids) == 1 - - if explicit_close: - textpage.close() - with caplog.at_level(logging.WARNING): - page.remove_obj(textobj) - - if explicit_close: - assert not caplog.text - else: - assert f"Removing text pageobbject implicitly closes affected textpage {textpage}." in caplog.text +# @pytest.mark.parametrize("explicit_close", [False, True]) +# def test_autoclose_with_remove_obj(caplog, explicit_close): +# +# pdf = pdfium.PdfDocument(TestFiles.text) +# page = pdf[0] +# textobj = next( page.get_objects(filter=[pdfium_c.FPDF_PAGEOBJ_TEXT]) ) +# assert len(page._kids) == 0 +# textpage = page.get_textpage() +# assert len(page._kids) == 1 +# +# if explicit_close: +# textpage.close() +# with caplog.at_level(logging.WARNING): +# page.remove_obj(textobj) +# +# if explicit_close: +# assert not caplog.text +# else: +# assert f"Removing text pageobbject implicitly closes affected textpage {textpage}." in caplog.text