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)
| 224 | |
| 225 | |
| 226 | def 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 | |
| 255 | def test_merge_checks1(): |
no test coverage detected
searching dependent graphs…