diff --git a/requirements/ci.in b/requirements/ci.in index d9f300412..a84af3881 100644 --- a/requirements/ci.in +++ b/requirements/ci.in @@ -3,6 +3,7 @@ flake8 flake8_implicit_str_concat flake8-bugbear flake8-print +fpdf2==2.4.1 mypy pillow pycryptodome diff --git a/requirements/ci.txt b/requirements/ci.txt index c80b3e62c..708904bfa 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -22,6 +22,8 @@ flake8-implicit-str-concat==0.2.0 # via -r requirements/ci.in flake8-print==4.0.1 # via -r requirements/ci.in +fpdf2==2.4.1 + # via -r requirements/ci.in importlib-metadata==4.2.0 # via # flake8 @@ -40,7 +42,9 @@ mypy-extensions==1.0.0 packaging==21.3 # via pytest pillow==8.4.0 - # via -r requirements/ci.in + # via + # -r requirements/ci.in + # fpdf2 pluggy==1.0.0 # via pytest py==1.11.0 diff --git a/tests/test_page.py b/tests/test_page.py index c8ed92cec..3cc09ff24 100644 --- a/tests/test_page.py +++ b/tests/test_page.py @@ -1174,3 +1174,32 @@ def test_image_new_property(): with pytest.raises(KeyError): reader.pages[0]._get_image(["test"], reader.pages[0]) assert list(PageObject(None, None).images) == [] + + +@pytest.mark.samples() +@pytest.mark.xfail(reason="issue #1897") +def test_compression(): + """Test for issue #1897""" + + def create_stamp_pdf() -> BytesIO: + from fpdf import FPDF + + pdf = FPDF() + pdf.add_page() + pdf.set_font("helvetica", "B", 16) + pdf.cell(40, 10, "Hello World!") + byte_string = pdf.output() + return BytesIO(byte_string) + + template = PdfReader(create_stamp_pdf()) + template_page = template.pages[0] + writer = PdfWriter() + writer.append(SAMPLE_ROOT / "009-pdflatex-geotopo/GeoTopo.pdf", [1]) + nb1 = len(writer._objects) + + for page in writer.pages: + page.merge_page(template_page) + assert len(writer._objects) == nb1 + 1 # font is added that's all + for page in writer.pages: + page.compress_content_streams() + assert len(writer._objects) == nb1 + 1