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

Function do_links

src_classic/utils.py:1493–1610  ·  view source on GitHub ↗

Insert links contained in copied page range into destination PDF. Parameter values **must** equal those of method insert_pdf(), which must have been previously executed.

(
    doc1: Document,
    doc2: Document,
    from_page: int = -1,
    to_page: int = -1,
    start_at: int = -1,
)

Source from the content-addressed store, hash-verified

1491
1492
1493def do_links(
1494 doc1: Document,
1495 doc2: Document,
1496 from_page: int = -1,
1497 to_page: int = -1,
1498 start_at: int = -1,
1499) -> None:
1500 """Insert links contained in copied page range into destination PDF.
1501
1502 Parameter values **must** equal those of method insert_pdf(), which must
1503 have been previously executed.
1504 """
1505
1506 # --------------------------------------------------------------------------
1507 # internal function to create the actual "/Annots" object string
1508 # --------------------------------------------------------------------------
1509 def cre_annot(lnk, xref_dst, pno_src, ctm):
1510 """Create annotation object string for a passed-in link."""
1511
1512 r = lnk["from"] * ctm # rect in PDF coordinates
1513 rect = "%g %g %g %g" % tuple(r)
1514 if lnk["kind"] == LINK_GOTO:
1515 txt = annot_skel["goto1"] # annot_goto
1516 idx = pno_src.index(lnk["page"])
1517 p = lnk["to"] * ctm # target point in PDF coordinates
1518 annot = txt % (xref_dst[idx], p.x, p.y, lnk["zoom"], rect)
1519
1520 elif lnk["kind"] == LINK_GOTOR:
1521 if lnk["page"] >= 0:
1522 txt = annot_skel["gotor1"] # annot_gotor
1523 pnt = lnk.get("to", Point(0, 0)) # destination point
1524 if type(pnt) is not Point:
1525 pnt = Point(0, 0)
1526 annot = txt % (
1527 lnk["page"],
1528 pnt.x,
1529 pnt.y,
1530 lnk["zoom"],
1531 lnk["file"],
1532 lnk["file"],
1533 rect,
1534 )
1535 else:
1536 txt = annot_skel["gotor2"] # annot_gotor_n
1537 to = get_pdf_str(lnk["to"])
1538 to = to[1:-1]
1539 f = lnk["file"]
1540 annot = txt % (to, f, rect)
1541
1542 elif lnk["kind"] == LINK_LAUNCH:
1543 txt = annot_skel["launch"] # annot_launch
1544 annot = txt % (lnk["file"], lnk["file"], rect)
1545
1546 elif lnk["kind"] == LINK_URI:
1547 txt = annot_skel["uri"] # annot_uri
1548 annot = txt % (lnk["uri"], rect)
1549
1550 else:

Callers

nothing calls this directly

Calls 5

cre_annotFunction · 0.85
page_xrefMethod · 0.80
get_linksMethod · 0.80
_addAnnot_FromStringMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…