MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / test_insert

Function test_insert

tests/test_insertpdf.py:60–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58
59
60def test_insert():
61 all_text_original = [] # text on input pages
62 all_text_combined = [] # text on resulting output pages
63 # prepare input PDFs
64 doc1 = pymupdf.open()
65 for i in range(5): # just arbitrary number of pages
66 text = f"doc 1, page {i}" # the 'globally' unique text
67 page = doc1.new_page()
68 page.insert_text((100, 72), text)
69 all_text_original.append(text)
70
71 doc2 = pymupdf.open()
72 for i in range(4):
73 text = f"doc 2, page {i}"
74 page = doc2.new_page()
75 page.insert_text((100, 72), text)
76 all_text_original.append(text)
77
78 doc3 = pymupdf.open()
79 for i in range(3):
80 text = f"doc 3, page {i}"
81 page = doc3.new_page()
82 page.insert_text((100, 72), text)
83 all_text_original.append(text)
84
85 doc4 = pymupdf.open()
86 for i in range(6):
87 text = f"doc 4, page {i}"
88 page = doc4.new_page()
89 page.insert_text((100, 72), text)
90 all_text_original.append(text)
91
92 new_doc = pymupdf.open() # make combined PDF of input files
93 new_doc.insert_pdf(doc1)
94 new_doc.insert_pdf(doc2)
95 new_doc.insert_pdf(doc3)
96 new_doc.insert_pdf(doc4)
97 # read text from all pages and store in list
98 for page in new_doc:
99 all_text_combined.append(page.get_text().replace("\n", ""))
100 # the lists must be equal
101 assert all_text_combined == all_text_original
102
103
104def test_issue1417_insertpdf_in_loop():

Callers

nothing calls this directly

Calls 5

new_pageMethod · 0.80
insert_pdfMethod · 0.80
insert_textMethod · 0.45
appendMethod · 0.45
get_textMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…