Add Web Link
Contents
[
Hide
]
Web links in PDFs allow users to navigate directly to online resources, websites, or documentation. Using PdfContentEditor, you can define a rectangular area on a PDF page that, when clicked, opens a URL in the default web browser.
- Create a PdfContentEditor instance.
- Bind the input PDF document.
- Define a rectangle for the clickable web link.
- Specifie the URL, page number, and link color.
- Save the updated PDF document.
import aspose.pdf.facades as pdf_facades
from aspose.pycore import cast, is_assignable
import aspose.pydrawing as apd
import aspose.pdf as ap
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def add_web_link(infile, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Add a web link annotation to page 1
content_editor.create_web_link(
apd.Rectangle(100, 650, 200, 20),
"https://products.aspose.com/pdf/python-net/",
1,
apd.Color.blue,
)
# Save updated document
content_editor.save(outfile)