设置现有PDF的XMP元数据 - 外观
Contents
[
Hide
]
为了在PDF文件中设置XMP元数据,您需要创建PdfXmpMetadata对象,并使用bindPdf(..)方法绑定PDF文件。 你可以使用 PdfXmpMetadata 类的 setByDefaultMetadataProperties(..) 方法来添加不同的属性。最后,调用 PdfXmpMetadata 类的 save(…) 方法。
以下代码片段向您展示了如何在 PDF 文件中添加 XMP 元数据。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.Pdf-for-Java | |
// create PdfXmpMetadata object | |
PdfXmpMetadata xmpMetaData = new PdfXmpMetadata(); | |
// bind pdf file to the object | |
xmpMetaData.bindPdf("input.pdf"); | |
// add create date | |
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.CreateDate, new java.util.Date()); | |
// change meta data date | |
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.MetadataDate, new java.util.Date()); | |
// add creator tool | |
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.CreatorTool, "Creator tool name"); | |
// add Nick for MetaData | |
xmpMetaData.setByDefaultMetadataProperties(DefaultMetadataProperties.Nickname, "Aspose Nick"); | |
// remove modify date | |
xmpMetaData.remove(DefaultMetadataProperties.ModifyDate); | |
// add user defined property | |
// step #1: register namespace prefix and URI | |
xmpMetaData.registerNamespaceURI("customNamespace", "http://www.customNameSpaces.com/ns/"); | |
// step #2: add user property with the prefix | |
xmpMetaData.addItem("customNamespace:UserPropertyName", "UserPropertyValue"); | |
// save xmp meta data in the pdf file | |
xmpMetaData.save("Updated_MetaData.pdf"); | |
// close the object | |
xmpMetaData.close(); |