在 PDF 中替换图像
Contents
[
Hide
]
PDF 通常包含可能需要更新或替换的图像,例如徽标、图表或照片。使用 PdfContentEditor,您可以通过提供页码、图像索引和新图像文件路径来替换给定页面上的特定图像。
- 创建一个 PdfContentEditor 实例。
- 绑定输入的 PDF 文档。
- 替换给定页面上的特定图像。
- 保存更新后的 PDF 文档。
import aspose.pdf.facades as pdf_facades
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def replace_image(infile, image_file, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Replace image on page 1
content_editor.replace_image(1, 1, image_file)
# Save updated document
content_editor.save(outfile)