使用 Java 删除 PDF 文件中的图像

当需要从 PDF 页面中删除嵌入图像时,请使用页面图像资源集合。

通过索引删除嵌入的图像

  1. 打开源 PDF Document。
  2. 访问目标上的图像资源 Page。
  3. 通过索引从页面资源集合中删除目标图像。
  4. 保存已更新的 PDF Document。
public static void deleteImage(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        document.getPages().get_Item(1).getResources().getImages().delete(1);
        document.save(outputFile.toString());
    }
}