Add Web Link

Contents
[ ]

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.

  1. Create a PdfContentEditor instance.
  2. Bind the input PDF document.
  3. Define a rectangle for the clickable web link.
  4. Specifie the URL, page number, and link color.
  5. 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)