这是对如何从 Java 中的 Word 文档中清除元数据的快速介绍。它包含有关设置 IDE 的详细信息、编程步骤列表以及用于从 Java 中的 Word 中删除元数据的可运行示例代码。您将学习完全删除属性以及仅删除值以及仅处理所选属性的选项。
在 Java 中从 Word 文档中删除元数据的步骤
- 建立使用 Aspose.Words for Java 的环境来清除属性
- 加载存在内置和自定义属性的 Word document
- 使用 getCustomDocumentProperties() 方法访问自定义属性
- 从 CustomDocumentProperties 类调用 clear() 方法以删除属性
- 调用 getBuiltInDocumentProperties() 方法来访问内置属性
- 调用 clear() 方法删除值和 save 文件
此过程解释了如何删除 Java 中的所有文档属性和个人信息。要完全删除属性,请调用 CustomDocumentProperties 类中的 clear() 方法,而要删除永久属性的值,请调用 clear() 方法。
在 Java 中从 Word 文档中清除元数据的代码
import com.aspose.words.*; | |
public class Main { | |
public static void main(String[] args) throws Exception // Remove Word file metadata in Java | |
{ | |
// Set the licenses | |
new com.aspose.words.License().setLicense("Aspose.Total.lic"); | |
// Load the Word DOC file | |
Document doc = new Document("SampleProps.doc"); | |
// Get the custom properties and remove them | |
CustomDocumentProperties custProps = doc.getCustomDocumentProperties(); | |
custProps.clear(); | |
// Get the built-in properties and remove the values | |
BuiltInDocumentProperties builtInProps = doc.getBuiltInDocumentProperties(); | |
builtInProps.clear(); | |
// Save the Word file | |
doc.save("Output.doc"); | |
System.out.println("Done"); | |
} | |
} |
此代码演示了删除 Java 中的所有文档属性和个人信息的过程。不同的选项可用于使用 remove() 方法删除所选属性,方法是提供名称并通过提供相应的属性索引调用相同的方法。您还可以使用 add() 方法通过提供属性名称和值来添加自定义属性。
本文指导我们删除 Java 中的所有文档属性和个人信息。如果您想了解编辑元数据的过程,请参阅 如何在 Java 中编辑 Word 文档元数据 上的文章。