添加自定义操作链接
Contents
[
Hide
]
自定义操作链接允许您在 PDF 中定义交互区域,点击时可触发特定操作,例如执行脚本、导航页面或运行特定应用程序的命令。Using PdfContentEditor, 您可以通过指定页面、矩形、颜色和操作来创建自定义操作链接。
- 创建一个 PdfContentEditor 实例。
- 绑定输入的 PDF 文档。
- 为可点击链接定义一个矩形。
- 指定页码和链接颜色。
- 分配自定义操作(本示例为空)。
- 保存更新后的 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_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)