Recursively follow the outline item chain and record item information in a list.
(olItem, liste, lvl)
| 5204 | simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation. |
| 5205 | """ |
| 5206 | def recurse(olItem, liste, lvl): |
| 5207 | """Recursively follow the outline item chain and record item information in a list.""" |
| 5208 | while olItem and olItem.this.m_internal: |
| 5209 | if olItem.title: |
| 5210 | title = olItem.title |
| 5211 | else: |
| 5212 | title = " " |
| 5213 | |
| 5214 | if not olItem.is_external: |
| 5215 | if olItem.uri: |
| 5216 | if olItem.page == -1: |
| 5217 | resolve = doc.resolve_link(olItem.uri) |
| 5218 | page = resolve[0] + 1 |
| 5219 | else: |
| 5220 | page = olItem.page + 1 |
| 5221 | else: |
| 5222 | page = -1 |
| 5223 | else: |
| 5224 | page = -1 |
| 5225 | |
| 5226 | if not simple: |
| 5227 | link = utils.getLinkDict(olItem, doc) |
| 5228 | liste.append([lvl, title, page, link]) |
| 5229 | else: |
| 5230 | liste.append([lvl, title, page]) |
| 5231 | |
| 5232 | if olItem.down: |
| 5233 | liste = recurse(olItem.down, liste, lvl + 1) |
| 5234 | olItem = olItem.next |
| 5235 | return liste |
| 5236 | |
| 5237 | # ensure document is open |
| 5238 | if doc.is_closed: |
nothing calls this directly
no test coverage detected