Ganti Gambar dalam PDF

Contents
[ ]

PDF sering berisi gambar yang mungkin perlu diperbarui atau diganti, seperti logo, diagram, atau foto. Dengan PdfContentEditor, Anda dapat mengganti gambar tertentu pada halaman tertentu dengan memberikan nomor halaman, indeks gambar, dan jalur file gambar baru.

  1. Buat instance PdfContentEditor.
  2. Hubungkan dokumen PDF masukan.
  3. Ganti gambar tertentu pada halaman yang diberikan.
  4. Simpan dokumen PDF yang diperbarui.
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)