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

Function getDestStr

src_classic/utils.py:1258–1313  ·  view source on GitHub ↗

Calculate the PDF action string. Notes: Supports Link annotations and outline items (bookmarks).

(xref: int, ddict: dict)

Source from the content-addressed store, hash-verified

1256
1257
1258def getDestStr(xref: int, ddict: dict) -> str:
1259 """Calculate the PDF action string.
1260
1261 Notes:
1262 Supports Link annotations and outline items (bookmarks).
1263 """
1264 if not ddict:
1265 return ""
1266 str_goto = "/A<</S/GoTo/D[%i 0 R/XYZ %g %g %g]>>"
1267 str_gotor1 = "/A<</S/GoToR/D[%s /XYZ %g %g %g]/F<</F%s/UF%s/Type/Filespec>>>>"
1268 str_gotor2 = "/A<</S/GoToR/D%s/F<</F%s/UF%s/Type/Filespec>>>>"
1269 str_launch = "/A<</S/Launch/F<</F%s/UF%s/Type/Filespec>>>>"
1270 str_uri = "/A<</S/URI/URI%s>>"
1271
1272 if type(ddict) in (int, float):
1273 dest = str_goto % (xref, 0, ddict, 0)
1274 return dest
1275 d_kind = ddict.get("kind", LINK_NONE)
1276
1277 if d_kind == LINK_NONE:
1278 return ""
1279
1280 if ddict["kind"] == LINK_GOTO:
1281 d_zoom = ddict.get("zoom", 0)
1282 to = ddict.get("to", Point(0, 0))
1283 d_left, d_top = to
1284 dest = str_goto % (xref, d_left, d_top, d_zoom)
1285 return dest
1286
1287 if ddict["kind"] == LINK_URI:
1288 dest = str_uri % (get_pdf_str(ddict["uri"]),)
1289 return dest
1290
1291 if ddict["kind"] == LINK_LAUNCH:
1292 fspec = get_pdf_str(ddict["file"])
1293 dest = str_launch % (fspec, fspec)
1294 return dest
1295
1296 if ddict["kind"] == LINK_GOTOR and ddict["page"] < 0:
1297 fspec = get_pdf_str(ddict["file"])
1298 dest = str_gotor2 % (get_pdf_str(ddict["to"]), fspec, fspec)
1299 return dest
1300
1301 if ddict["kind"] == LINK_GOTOR and ddict["page"] >= 0:
1302 fspec = get_pdf_str(ddict["file"])
1303 dest = str_gotor1 % (
1304 ddict["page"],
1305 ddict["to"].x,
1306 ddict["to"].y,
1307 ddict["zoom"],
1308 fspec,
1309 fspec,
1310 )
1311 return dest
1312
1313 return ""
1314
1315

Callers 2

set_toc_itemFunction · 0.70
set_tocFunction · 0.70

Calls 3

PointClass · 0.85
get_pdf_strFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…