MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / _delToC

Method _delToC

src/__init__.py:3087–3117  ·  view source on GitHub ↗

Delete the TOC.

(self)

Source from the content-addressed store, hash-verified

3085 self._remove_toc_item(xref)
3086
3087 def _delToC(self):
3088 """Delete the TOC."""
3089 if self.is_closed or self.is_encrypted:
3090 raise ValueError("document closed or encrypted")
3091 xrefs = [] # create Python list
3092 pdf = _as_pdf_document(self, required=0)
3093 if not pdf.m_internal:
3094 return xrefs # not a pdf
3095 # get the main root
3096 root = mupdf.pdf_dict_get(mupdf.pdf_trailer(pdf), PDF_NAME('Root'))
3097 # get the outline root
3098 olroot = mupdf.pdf_dict_get(root, PDF_NAME('Outlines'))
3099 if not olroot.m_internal:
3100 return xrefs # no outlines or some problem
3101
3102 first = mupdf.pdf_dict_get(olroot, PDF_NAME('First')) # first outline
3103
3104 xrefs = JM_outline_xrefs(first, xrefs)
3105 xref_count = len(xrefs)
3106
3107 olroot_xref = mupdf.pdf_to_num(olroot) # delete OL root
3108 mupdf.pdf_delete_object(pdf, olroot_xref) # delete OL root
3109 mupdf.pdf_dict_del(root, PDF_NAME('Outlines')) # delete OL root
3110
3111 for i in range(xref_count):
3112 _, xref = JM_INT_ITEM(xrefs, i)
3113 mupdf.pdf_delete_object(pdf, xref) # delete outline item
3114 xrefs.append(olroot_xref)
3115 val = xrefs
3116 self.init_doc()
3117 return val
3118
3119 def _delete_page(self, pno):
3120 pdf = _as_pdf_document(self)

Callers 2

set_tocMethod · 0.80
set_tocFunction · 0.80

Calls 7

init_docMethod · 0.95
_as_pdf_documentFunction · 0.85
PDF_NAMEFunction · 0.85
JM_outline_xrefsFunction · 0.85
JM_INT_ITEMFunction · 0.85
pdf_trailerMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected