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

Function test_widget_insert

tests/test_insertpdf.py:192–223  ·  view source on GitHub ↗

Confirm copy of form fields / widgets.

()

Source from the content-addressed store, hash-verified

190
191
192def test_widget_insert():
193 """Confirm copy of form fields / widgets."""
194 tar = pymupdf.open(os.path.join(resources, "merge-form1.pdf"))
195 pc0 = tar.page_count # for later assertion
196 src = pymupdf.open(os.path.join(resources, "interfield-calculation.pdf"))
197 pc1 = src.page_count # for later assertion
198
199 tarpdf = pymupdf._as_pdf_document(tar)
200 tar_field_count = mupdf.pdf_array_len(
201 mupdf.pdf_dict_getp(mupdf.pdf_trailer(tarpdf), "Root/AcroForm/Fields")
202 )
203 tar_co_count = mupdf.pdf_array_len(
204 mupdf.pdf_dict_getp(mupdf.pdf_trailer(tarpdf), "Root/AcroForm/CO")
205 )
206 srcpdf = pymupdf._as_pdf_document(src)
207 src_field_count = mupdf.pdf_array_len(
208 mupdf.pdf_dict_getp(mupdf.pdf_trailer(srcpdf), "Root/AcroForm/Fields")
209 )
210 src_co_count = mupdf.pdf_array_len(
211 mupdf.pdf_dict_getp(mupdf.pdf_trailer(srcpdf), "Root/AcroForm/CO")
212 )
213
214 tar.insert_pdf(src)
215 new_field_count = mupdf.pdf_array_len(
216 mupdf.pdf_dict_getp(mupdf.pdf_trailer(tarpdf), "Root/AcroForm/Fields")
217 )
218 new_co_count = mupdf.pdf_array_len(
219 mupdf.pdf_dict_getp(mupdf.pdf_trailer(tarpdf), "Root/AcroForm/CO")
220 )
221 assert tar.page_count == pc0 + pc1
222 assert new_field_count == tar_field_count + src_field_count
223 assert new_co_count == tar_co_count + src_co_count
224
225
226def names_and_kids(doc):

Callers

nothing calls this directly

Calls 2

pdf_trailerMethod · 0.80
insert_pdfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…