Add Application Link

Contents
[ ]

PDF can include interactive elements such as links that launch external applications. Using PdfContentEditor, you can define a rectangular region on a page that, when clicked, opens a specific executable file.

  1. Create a PdfContentEditor instance.
  2. Bind the input PDF document.
  3. Define a rectangle area for the clickable link.
  4. Specifie the application path to launch.
  5. Set the link color.
  6. 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_application_link(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Add application launch link
    content_editor.create_application_link(
        apd.Rectangle(180, 530, 260, 20),
        "notepad.exe",
        1,
        apd.Color.purple,
    )
    # Save updated document
    content_editor.save(outfile)