Operasi gambar

Java saat ini kelas PdfContentEditorExamples secara langsung mendukung replaceImage(...).

Mengganti gambar

  1. Ikat PDF sumber ke fasad PdfContentEditor.
  2. Panggil replaceImage(...) dengan nomor halaman, indeks gambar, dan jalur gambar pengganti.
  3. Simpan dokumen PDF yang diperbarui.
public static void replaceImage(Path inputFile, Path imageFile, Path outputFile) {
    PdfContentEditor editor = new PdfContentEditor();
    try {
        editor.bindPdf(inputFile.toString());
        editor.replaceImage(1, 1, imageFile.toString());
        editor.save(outputFile.toString());
    } finally {
        editor.close();
    }
}