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,
)
| 3130 | mupdf.pdf_delete_object(pdf, xref) |
| 3131 | |
| 3132 | def _do_links( |
| 3133 | doc1: 'Document', |
| 3134 | doc2: 'Document', |
| 3135 | from_page: int = -1, |
| 3136 | to_page: int = -1, |
| 3137 | start_at: int = -1, |
| 3138 | ) -> None: |
| 3139 | """Insert links contained in copied page range into destination PDF. |
| 3140 | |
| 3141 | Parameter values **must** equal those of method insert_pdf(), which must |
| 3142 | have been previously executed. |
| 3143 | """ |
| 3144 | #pymupdf.log( 'utils.do_links()') |
| 3145 | # -------------------------------------------------------------------------- |
| 3146 | # internal function to create the actual "/Annots" object string |
| 3147 | # -------------------------------------------------------------------------- |
| 3148 | def cre_annot(lnk, xref_dst, pno_src, ctm): |
| 3149 | """Create annotation object string for a passed-in link.""" |
| 3150 | |
| 3151 | r = lnk["from"] * ctm # rect in PDF coordinates |
| 3152 | rect = _format_g(tuple(r)) |
| 3153 | if lnk["kind"] == LINK_GOTO: |
| 3154 | txt = annot_skel["goto1"] # annot_goto |
| 3155 | idx = pno_src.index(lnk["page"]) |
| 3156 | p = lnk["to"] * ctm # target point in PDF coordinates |
| 3157 | annot = txt(xref_dst[idx], p.x, p.y, lnk["zoom"], rect) |
| 3158 | |
| 3159 | elif lnk["kind"] == LINK_GOTOR: |
| 3160 | if lnk["page"] >= 0: |
| 3161 | txt = annot_skel["gotor1"] # annot_gotor |
| 3162 | pnt = lnk.get("to", Point(0, 0)) # destination point |
| 3163 | if type(pnt) is not Point: |
| 3164 | pnt = Point(0, 0) |
| 3165 | annot = txt( |
| 3166 | lnk["page"], |
| 3167 | pnt.x, |
| 3168 | pnt.y, |
| 3169 | lnk["zoom"], |
| 3170 | lnk["file"], |
| 3171 | lnk["file"], |
| 3172 | rect, |
| 3173 | ) |
| 3174 | else: |
| 3175 | txt = annot_skel["gotor2"] # annot_gotor_n |
| 3176 | to = get_pdf_str(lnk["to"]) |
| 3177 | to = to[1:-1] |
| 3178 | f = lnk["file"] |
| 3179 | annot = txt(to, f, rect) |
| 3180 | |
| 3181 | elif lnk["kind"] == LINK_LAUNCH: |
| 3182 | txt = annot_skel["launch"] # annot_launch |
| 3183 | annot = txt(lnk["file"], lnk["file"], rect) |
| 3184 | |
| 3185 | elif lnk["kind"] == LINK_URI: |
| 3186 | txt = annot_skel["uri"] # annot_uri |
| 3187 | annot = txt(lnk["uri"], rect) |
| 3188 | |
| 3189 | else: |
no test coverage detected