def do_links(doc1, doc2, from_page = -<NUM_LIT:1>, to_page = -<NUM_LIT:1>, start_at = -<NUM_LIT:1>):
<EOL>annot_goto ='''<STR_LIT>'''<EOL>annot_gotor = '''<STR_LIT>'''<EOL>annot_gotor_n = "<STR_LIT>"<EOL>annot_launch = '''<STR_LIT>'''<EOL>annot_uri = '''<STR_LIT>'''<EOL>def cre_annot(lnk, xref_dst, list_src, height):<EOL><INDENT>'''<STR_LIT>'''<EOL>r = lnk["<STR_LIT>"]<EOL>rect = "<STR_LIT>" % (r.x0, height - r.y0, r.x1, height - r.y1)<EOL>if lnk["<STR_LIT>"] == LINK_GOTO:<EOL><INDENT>txt = annot_goto<EOL>idx = list_src.index(lnk["<STR_LIT>"])<EOL>annot = txt % (xref_dst[idx], lnk["<STR_LIT:to>"].x,<EOL>lnk["<STR_LIT:to>"].y, rect)<EOL><DEDENT>elif lnk["<STR_LIT>"] == LINK_GOTOR:<EOL><INDENT>if lnk["<STR_LIT>"] >= <NUM_LIT:0>:<EOL><INDENT>txt = annot_gotor<EOL>pnt = lnk.get("<STR_LIT:to>", Point(<NUM_LIT:0>, <NUM_LIT:0>))          <EOL>if type(pnt) is not Point:<EOL><INDENT>pnt = Point(<NUM_LIT:0>, <NUM_LIT:0>)<EOL><DEDENT>annot = txt % (lnk["<STR_LIT>"], pnt.x, pnt.y,<EOL>lnk["<STR_LIT:file>"], lnk["<STR_LIT:file>"], rect)<EOL><DEDENT>else:<EOL><INDENT>txt = annot_gotor_n<EOL>to = getPDFstr(lnk["<STR_LIT:to>"])<EOL>to = to[<NUM_LIT:1>:-<NUM_LIT:1>]<EOL>f = lnk["<STR_LIT:file>"]<EOL>annot = txt % (to, f, rect)<EOL><DEDENT><DEDENT>elif lnk["<STR_LIT>"] == LINK_LAUNCH:<EOL><INDENT>txt = annot_launch<EOL>annot = txt % (lnk["<STR_LIT:file>"], lnk["<STR_LIT:file>"], rect)<EOL><DEDENT>elif lnk["<STR_LIT>"] == LINK_URI:<EOL><INDENT>txt = annot_uri<EOL>annot = txt % (lnk["<STR_LIT>"], rect)<EOL><DEDENT>else:<EOL><INDENT>annot = "<STR_LIT>"<EOL><DEDENT>return annot<EOL><DEDENT>if from_page < <NUM_LIT:0>:<EOL><INDENT>fp = <NUM_LIT:0><EOL><DEDENT>elif from_page >= doc2.pageCount:<EOL><INDENT>from_page = doc2.pageCount - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>fp = from_page<EOL><DEDENT>if to_page < <NUM_LIT:0> or to_page >= doc2.pageCount:<EOL><INDENT>tp = doc2.pageCount - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>tp = to_page<EOL><DEDENT>if start_at < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>sa = start_at<EOL>incr = <NUM_LIT:1> if fp <= tp else -<NUM_LIT:1>            <EOL>list_src = list(range(fp, tp + incr, incr))<EOL>list_dst = [sa + i for i in range(len(list_src))]<EOL>xref_src = []<EOL>xref_dst = []<EOL>for i in range(len(list_src)):<EOL><INDENT>p_src = list_src[i]<EOL>p_dst = list_dst[i]<EOL>old_xref = doc2._getPageObjNumber(p_src)[<NUM_LIT:0>]<EOL>new_xref = doc1._getPageObjNumber(p_dst)[<NUM_LIT:0>]<EOL>xref_src.append(old_xref)<EOL>xref_dst.append(new_xref)<EOL><DEDENT>for i in range(len(xref_src)):<EOL><INDENT>page_src = doc2[list_src[i]]<EOL>links = page_src.getLinks()<EOL>if len(links) == <NUM_LIT:0>:<EOL><INDENT>page_src = None<EOL>continue<EOL><DEDENT>height = page_src.bound().y1<EOL>p_annots = "<STR_LIT>"<EOL>page_dst = doc1[list_dst[i]]<EOL>link_tab = []<EOL>for l in links:<EOL><INDENT>if l["<STR_LIT>"] == LINK_GOTO and (l["<STR_LIT>"] not in list_src):<EOL><INDENT>continue          <EOL><DEDENT>annot_text = cre_annot(l, xref_dst, list_src, height)<EOL>if not annot_text:<EOL><INDENT>print("<STR_LIT>" + str(l["<STR_LIT>"]))<EOL><DEDENT>else:<EOL><INDENT>link_tab.append(annot_text)<EOL><DEDENT><DEDENT>if len(link_tab) > <NUM_LIT:0>:<EOL><INDENT>page_dst._addAnnot_FromString(link_tab)<EOL><DEDENT>page_dst = None<EOL>page_src = None<EOL><DEDENT>return<EOL>
Insert links contained in copied page range into destination PDF.
    Parameter values **must** equal those of method insertPDF() - which must have been previously executed.