Create a link to a named destination in a PDF file with PymuPDF

149 Views Asked by At

I wanted to create a link that is associated with a named destination of a PDF file using PymuPDF, The program runs, but it doesn't create t any link.

# Import the PyMuPDF library
import fitz
# Open the source PDF file
doc = fitz.open("pdf-with-named-destination.pdf")
from_rect=fitz.Rect(50, 50, 100,100)

# Get the fourth page of the source PDF file
page = doc\[3\]
# Define the named link
namedlink={"kind": fitz.LINK_NAMED
    , "name": "nameddest=anchor4"
    , "from": from_rect  
}


# Insert the link to the page`your text`
page.insert_link(namedlink)
idx=0

# Print links

for page in doc:
    idx = idx + 1
    links=page.get_links()
    if len(links) \> 0:
        print("------ Page No.: " + str(idx)+"------:")

        for link in links:
        print(link)
        print("\n")

# Save the modified source PDF file
doc.save("pdf-with-named-destination-link.pdf")
doc.close()
doc=None
0

There are 0 best solutions below