如何使用Fitz模块为超链接添加边框



今天早上我花了三个小时对此进行了实验,但我无法在用python FITZ模块注释的pdf中的超链接上显示边框。知道吗?提前感谢!

import fitz
doc = fitz.open("test.pdf")
page = doc[0]
d = {'kind': 2, 'xref': 0, 'from': fitz.Rect(90, 240, 200, 270), 'uri': 'https://www.google.fr', 'id': ''}
page.insert_link(d)
lnk = page.first_link
while lnk:
    lnk.set_border(width=1.0, dashes=[], style='S')
    lnk.set_colors(stroke=(1,0,1))
    lnk = lnk.next
doc.saveIncr() 
def format_links(doc):
    red   = (1.0, 0.0, 0.0)
    green = (0.0, 1.0, 0.0)
    border = {'width': 1.0, 'dashes': [], 'style': None}
    internal_link_colors = {'stroke': red,   'fill': None}
    external_link_colors = {'stroke': green, 'fill': None}
    for page in doc:
        link = page.load_links()
        while link != None:
            if (link.is_external):
                link.set_border(border)
                link.set_colors(external_link_colors)
            else:
                link.set_border(border)
                link.set_colors(internal_link_colors)
            link = link.next

最新更新