MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / names_and_kids

Function names_and_kids

tests/test_insertpdf.py:226–252  ·  view source on GitHub ↗

Return a list of dictionaries with keys "name" and "kids". "name" is the name of a root field in "Root/AcroForm/Fields", and "kids" is the count of its immediate children.

(doc)

Source from the content-addressed store, hash-verified

224
225
226def names_and_kids(doc):
227 """Return a list of dictionaries with keys "name" and "kids".
228
229 "name" is the name of a root field in "Root/AcroForm/Fields", and
230 "kids" is the count of its immediate children.
231 """
232 rc = []
233 pdf = pymupdf._as_pdf_document(doc)
234 fields = mupdf.pdf_dict_getl(
235 mupdf.pdf_trailer(pdf),
236 pymupdf.PDF_NAME("Root"),
237 pymupdf.PDF_NAME("AcroForm"),
238 pymupdf.PDF_NAME("Fields"),
239 )
240 if not fields.pdf_is_array():
241 return rc
242 root_count = fields.pdf_array_len()
243 if not root_count:
244 return rc
245 for i in range(root_count):
246 field = fields.pdf_array_get(i)
247 kids = field.pdf_dict_get(pymupdf.PDF_NAME("Kids"))
248 kid_count = kids.pdf_array_len()
249 T = field.pdf_dict_get_text_string(pymupdf.PDF_NAME("T"))
250 field_dict = {"name": T, "kids": kid_count}
251 rc.append(field_dict)
252 return rc
253
254
255def test_merge_checks1():

Callers 2

test_merge_checks1Function · 0.85
test_merge_checks2Function · 0.85

Calls 2

pdf_trailerMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…