diff --git a/tests/test_writer.py b/tests/test_writer.py index 358fdb1cf..00d3e513f 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -1859,3 +1859,31 @@ def test_object_contains_indirect_reference_to_self(): outpage = writer.add_blank_page(width, height) outpage.merge_page(reader.pages[6]) writer.append(reader) + + +def test_merging_many_temporary_files(): + def create_number_pdf(n) -> BytesIO: + from fpdf import FPDF + + pdf = FPDF() + pdf.add_page() + pdf.set_font("helvetica", "B", 16) + pdf.cell(40, 10, str(n)) + byte_string = pdf.output() + return BytesIO(byte_string) + + writer = PdfWriter() + for n in range(100): + reader = PdfReader(create_number_pdf(n)) + for page in reader.pages: + # Should only be one page. + writer.add_page(page) + + out = BytesIO() + writer.write(out) + + out.seek(0) + reader = PdfReader(out) + for n, page in enumerate(reader.pages): + text = page.extract_text() + assert text == str(n)