2

I spent three hours experimenting this morning on this but I can't manage to make the border visible on a hyperlink within a pdf annotated with the python FITZ module. Any idea ? Thanks so much in advance !

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() 

1 Answers1

0
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
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 27 '23 at 18:09