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

Method _addAnnot_FromString

src/__init__.py:9843–9875  ·  view source on GitHub ↗

Add links from list of object sources.

(self, linklist)

Source from the content-addressed store, hash-verified

9841 return val
9842
9843 def _addAnnot_FromString(self, linklist):
9844 """Add links from list of object sources."""
9845 CheckParent(self)
9846 if g_use_extra:
9847 self.__class__._addAnnot_FromString = extra.Page_addAnnot_FromString
9848 #log('Page._addAnnot_FromString() deferring to extra.Page_addAnnot_FromString().')
9849 return extra.Page_addAnnot_FromString( self.this, linklist)
9850 page = _as_pdf_page(self.this)
9851 lcount = len(linklist) # link count
9852 if lcount < 1:
9853 return
9854 i = -1
9855
9856 # insert links from the provided sources
9857 if not isinstance(linklist, tuple):
9858 raise ValueError( "bad 'linklist' argument")
9859 if not mupdf.pdf_dict_get( page.obj(), PDF_NAME('Annots')).m_internal:
9860 mupdf.pdf_dict_put_array( page.obj(), PDF_NAME('Annots'), lcount)
9861 annots = mupdf.pdf_dict_get( page.obj(), PDF_NAME('Annots'))
9862 assert annots.m_internal, f'{lcount=} {annots.m_internal=}'
9863 for i in range(lcount):
9864 txtpy = linklist[i]
9865 text = JM_StrAsChar(txtpy)
9866 if not text:
9867 message(f"skipping bad link / annot item {i:d}.")
9868 continue
9869 try:
9870 annot = mupdf.pdf_add_object( page.doc(), JM_pdf_obj_from_str( page.doc(), text))
9871 ind_obj = mupdf.pdf_new_indirect( page.doc(), mupdf.pdf_to_num( annot), 0)
9872 mupdf.pdf_array_push( annots, ind_obj)
9873 except Exception:
9874 if g_exceptions_verbose: exception_info()
9875 message(f"skipping bad link / annot item {i:d}.\n")
9876
9877 def _addWidget(self, field_type, field_name):
9878 page = self._pdf_page()

Callers 4

_do_linksMethod · 0.80
insert_linkMethod · 0.80
do_linksFunction · 0.80
insert_linkFunction · 0.80

Calls 7

CheckParentFunction · 0.85
_as_pdf_pageFunction · 0.85
PDF_NAMEFunction · 0.85
JM_StrAsCharFunction · 0.85
JM_pdf_obj_from_strFunction · 0.85
exception_infoFunction · 0.85
messageFunction · 0.70

Tested by

no test coverage detected