添加网页链接

Contents
[ ]

PDF 中的网页链接允许用户直接导航到在线资源、网站或文档。使用 PdfContentEditor,您可以在 PDF 页面上定义一个矩形区域,该区域在点击时会在默认网页浏览器中打开 URL。

  1. 创建一个 PdfContentEditor 实例。
  2. 绑定输入的 PDF 文档。
  3. 为可点击的网页链接定义一个矩形。
  4. 指定 URL、页码和链接颜色。
  5. 保存更新后的 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_web_link(infile, outfile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Add a web link annotation to page 1
    content_editor.create_web_link(
        apd.Rectangle(100, 650, 200, 20),
        "https://products.aspose.com/pdf/python-net/",
        1,
        apd.Color.blue,
    )
    # Save updated document
    content_editor.save(outfile)