图像操作

Contents
[ ]

当前的 Java PdfContentEditorExamples 类直接支持 replaceImage(...)。

替换图像

  1. 将源 PDF 绑定到 PdfContentEditor 立面。
  2. 调用 replaceImage(...) 带有页码、图像索引和替换图像路径。
  3. 保存更新后的 PDF 文档。
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();
    }
}