Add PDF Document Link

Contents
[ ]

PDF document links allow users to navigate from one PDF to another seamlessly. Using PdfContentEditor, you can define a clickable rectangle that links to a page in a different PDF file, making your documents interactive and connected.

  1. Create a PdfContentEditor instance.
  2. Bind the input PDF document.
  3. Define a rectangle for the clickable link.
  4. Specifie the linked PDF file, 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_pdf_document_link(infile, linked_pdf, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Add link to another PDF document
    content_editor.create_pdf_document_link(
        apd.Rectangle(140, 590, 240, 20),
        linked_pdf,
        1,
        1,
        apd.Color.green,
    )
    # Save updated document
    content_editor.save(outfile)