使用Java删除PDF元数据

JAV*_*VAC 6 pdf itext pdfbox

如何使用Java删除PDF上的元数据?

IText会做什么或任何其他框架都有能力做到这一点?我没有找到任何使用IText删除元数据的示例或类.如果有人之前做过这个或任何想法?

请分享您的观点.

提前致谢.

Lon*_*zak 5

首先,您需要区分,因为PDF中有两种类型的元数据:

  1. XMP元数据
  2. DID(文件信息词典,旧方式)

首先删除如下所示:

PdfReader reader = stamper.getReader();
reader.getCatalog().remove(PdfName.METADATA);
reader.removeUnusedObjects();
Run Code Online (Sandbox Code Playgroud)

像SANN3那样你删除的第二个提到:

HashMap<String, String> info = super.reader.getInfo();
info.put("Title", null);
info.put("Author", null);
info.put("Subject", null);
info.put("Keywords", null);
info.put("Creator", null);
info.put("Producer", null;
info.put("CreationDate", null);
info.put("ModDate", null);
info.put("Trapped", null);
stamper.setMoreInfo(info);
Run Code Online (Sandbox Code Playgroud)

如果您随后使用文本编辑器搜索PDF,则无法找到/ INFO字典或XMP元数据...