Add Custom Action Link
Contents
[
Hide
]
Custom action links allow you to define interactive areas in a PDF that can trigger specific actions when clicked, such as executing scripts, navigating pages, or running application-specific commands. Using PdfContentEditor, you can create a custom action link by specifying the page, rectangle, color, and actions.
- Create a PdfContentEditor instance.
- Bind the input PDF document.
- Define a rectangle for the clickable link.
- Specifie the page number and link color.
- Assign custom actions (empty in this example).
- 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_custom_action_link(infile, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Add custom action link. Empty action list keeps the sample runnable
# without requiring additional enum lookups.
content_editor.create_custom_action_link(
apd.Rectangle(200, 500, 260, 20),
1,
apd.Color.dark_red,
[],
)
# Save updated document
content_editor.save(outfile)