图像操作
Contents
[
Hide
]
当前的 Java PdfContentEditorExamples 类直接支持 replaceImage(...)。
替换图像
- 将源 PDF 绑定到
PdfContentEditor立面。 - 调用
replaceImage(...)带有页码、图像索引和替换图像路径。 - 保存更新后的 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();
}
}