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

Method delete_link

src/__init__.py:10905–10947  ·  view source on GitHub ↗

Delete a Link.

(self, linkdict)

Source from the content-addressed store, hash-verified

10903 page.replace_image(xref, pixmap=pix)
10904
10905 def delete_link(self, linkdict):
10906 """Delete a Link."""
10907 CheckParent(self)
10908 if not isinstance( linkdict, dict):
10909 return # have no dictionary
10910
10911 def finished():
10912 if linkdict["xref"] == 0: return
10913 try:
10914 linkid = linkdict["id"]
10915 linkobj = self._annot_refs[linkid]
10916 linkobj._erase()
10917 except Exception:
10918 # Don't print this exception, to match classic. Issue #2841.
10919 if g_exceptions_verbose > 1: exception_info()
10920 pass
10921
10922 page = _as_pdf_page(self.this, required=False)
10923 if not page.m_internal:
10924 return finished() # have no PDF
10925 xref = linkdict[dictkey_xref]
10926 if xref < 1:
10927 return finished() # invalid xref
10928 annots = mupdf.pdf_dict_get( page.obj(), PDF_NAME('Annots'))
10929 if not annots.m_internal:
10930 return finished() # have no annotations
10931 len_ = mupdf.pdf_array_len( annots)
10932 if len_ == 0:
10933 return finished()
10934 oxref = 0
10935 for i in range( len_):
10936 oxref = mupdf.pdf_to_num( mupdf.pdf_array_get( annots, i))
10937 if xref == oxref:
10938 break # found xref in annotations
10939
10940 if xref != oxref:
10941 return finished() # xref not in annotations
10942 mupdf.pdf_array_delete( annots, i) # delete entry in annotations
10943 mupdf.pdf_delete_object( page.doc(), xref) # delete link object
10944 mupdf.pdf_dict_put( page.obj(), PDF_NAME('Annots'), annots)
10945 JM_refresh_links( page)
10946
10947 return finished()
10948
10949 def delete_widget(page: 'Page', widget: Widget) -> Widget:
10950 """Delete widget from page and return the next one."""

Callers 3

remove_rotationMethod · 0.95
scrubMethod · 0.80
scrubFunction · 0.80

Calls 4

CheckParentFunction · 0.85
_as_pdf_pageFunction · 0.85
PDF_NAMEFunction · 0.85
JM_refresh_linksFunction · 0.85

Tested by

no test coverage detected