Add Local Link

Contents
[ ]

Local links in PDFs allow quick navigation between pages within the same document. Using PdfContentEditor, you can define a clickable rectangle that links one page to another, improving document usability and navigation.

  1. Create a PdfContentEditor instance.
  2. Bind the input PDF document.
  3. Define a rectangle for the clickable local link.
  4. Specifie the source page and destination page.
  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_local_link(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Add a local link on page 1 to destination page 1
    content_editor.create_local_link(
        apd.Rectangle(120, 620, 220, 20),
        1,
        1,
        apd.Color.red,
    )
    # Save updated document
    content_editor.save(outfile)