Update TOC item by index. It allows changing the item's title and link destination. Args: idx: (int) desired index of the TOC list, as created by get_toc. dest_dict: (dict) destination dictionary as created by get_toc(False).
(
doc: 'Document',
idx: int,
dest_dict: OptDict = None,
kind: OptInt = None,
pno: OptInt = None,
uri: OptStr = None,
title: OptStr = None,
to: point_like = None,
filename: OptStr = None,
zoom: float = 0,
)
| 7316 | return toclen |
| 7317 | |
| 7318 | def set_toc_item( |
| 7319 | doc: 'Document', |
| 7320 | idx: int, |
| 7321 | dest_dict: OptDict = None, |
| 7322 | kind: OptInt = None, |
| 7323 | pno: OptInt = None, |
| 7324 | uri: OptStr = None, |
| 7325 | title: OptStr = None, |
| 7326 | to: point_like = None, |
| 7327 | filename: OptStr = None, |
| 7328 | zoom: float = 0, |
| 7329 | ) -> None: |
| 7330 | """Update TOC item by index. |
| 7331 | |
| 7332 | It allows changing the item's title and link destination. |
| 7333 | |
| 7334 | Args: |
| 7335 | idx: |
| 7336 | (int) desired index of the TOC list, as created by get_toc. |
| 7337 | dest_dict: |
| 7338 | (dict) destination dictionary as created by get_toc(False). |
| 7339 | Outrules all other parameters. If None, the remaining parameters |
| 7340 | are used to make a dest dictionary. |
| 7341 | kind: |
| 7342 | (int) kind of link (pymupdf.LINK_GOTO, etc.). If None, then only |
| 7343 | the title will be updated. If pymupdf.LINK_NONE, the TOC item will |
| 7344 | be deleted. |
| 7345 | pno: |
| 7346 | (int) page number (1-based like in get_toc). Required if |
| 7347 | pymupdf.LINK_GOTO. |
| 7348 | uri: |
| 7349 | (str) the URL, required if pymupdf.LINK_URI. |
| 7350 | title: |
| 7351 | (str) the new title. No change if None. |
| 7352 | to: |
| 7353 | (point-like) destination on the target page. If omitted, (72, 36) |
| 7354 | will be used as target coordinates. |
| 7355 | filename: |
| 7356 | (str) destination filename, required for pymupdf.LINK_GOTOR and |
| 7357 | pymupdf.LINK_LAUNCH. |
| 7358 | name: |
| 7359 | (str) a destination name for pymupdf.LINK_NAMED. |
| 7360 | zoom: |
| 7361 | (float) a zoom factor for the target location (pymupdf.LINK_GOTO). |
| 7362 | """ |
| 7363 | xref = doc.get_outline_xrefs()[idx] |
| 7364 | page_xref = 0 |
| 7365 | if type(dest_dict) is dict: |
| 7366 | if dest_dict["kind"] == LINK_GOTO: |
| 7367 | pno = dest_dict["page"] |
| 7368 | page_xref = doc.page_xref(pno) |
| 7369 | page_height = doc.page_cropbox(pno).height |
| 7370 | to = dest_dict.get('to', Point(72, 36)) |
| 7371 | to.y = page_height - to.y |
| 7372 | dest_dict["to"] = to |
| 7373 | action = utils.getDestStr(page_xref, dest_dict) |
| 7374 | if not action.startswith("/A"): |
| 7375 | raise ValueError("bad bookmark dest") |