Add a unique /NM key to an annotation or widget. Append a number to 'stem' such that the result is a unique name.
(annot, stem)
| 18559 | |
| 18560 | |
| 18561 | def JM_add_annot_id(annot, stem): |
| 18562 | ''' |
| 18563 | Add a unique /NM key to an annotation or widget. |
| 18564 | Append a number to 'stem' such that the result is a unique name. |
| 18565 | ''' |
| 18566 | assert isinstance(annot, mupdf.PdfAnnot) |
| 18567 | page = _pdf_annot_page(annot) |
| 18568 | annot_obj = mupdf.pdf_annot_obj( annot) |
| 18569 | names = JM_get_annot_id_list(page) |
| 18570 | i = 0 |
| 18571 | while 1: |
| 18572 | stem_id = f'{JM_annot_id_stem}-{stem}{i}' |
| 18573 | if stem_id not in names: |
| 18574 | break |
| 18575 | i += 1 |
| 18576 | response = JM_StrAsChar(stem_id) |
| 18577 | name = mupdf.pdf_new_string( response, len(response)) |
| 18578 | mupdf.pdf_dict_puts(annot_obj, "NM", name) |
| 18579 | page.doc().m_internal.resynth_required = 0 |
| 18580 | |
| 18581 | |
| 18582 | def JM_add_oc_object(pdf, ref, xref): |
no test coverage detected
searching dependent graphs…