添加本地链接
Contents
[
Hide
]
本地链接在 PDF 中允许在同一文档的页面之间快速导航。使用 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_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)