添加应用链接

Contents
[ ]

PDF 可以包含交互式元素,例如启动外部应用程序的链接。使用 PdfContentEditor,您可以在页面上定义一个矩形区域,点击后打开特定的可执行文件。

  1. 创建一个 PdfContentEditor 实例。
  2. 绑定输入的 PDF 文档。
  3. 为可点击链接定义一个矩形区域。
  4. 指定要启动的应用程序路径。
  5. 设置链接颜色。
  6. 保存更新后的 PDF 文档。
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)