雲開發人員的又一個消息! GroupDocs 推出了文檔元數據操作雲 API。這豐富了GroupDocs的文檔元數據管理解決方案。該解決方案已經為 .NET 和 Java 開發人員提供服務,作為開發人員的 On-Premise API,以及任何類型的用戶查看和編輯文檔元數據的 免費在線文檔元數據編輯器應用程序

元數據操作雲API

GroupDocs.雲元數據

GroupDocs.Metadata Cloud API 以及 SDK 允許開發人員操作(添加、刪除、更新、提取和查看)50 多種文件格式的元數據。

GroupDocs.Metadata 允許以不同的方式訪問和處理文件的元數據,例如:

  • 可能的標籤名稱
  • 物業名稱
  • 適當的價值
  • 精確匹配短語
  • 匹配正則表達式
  • 整個元數據樹
  • 標籤

要更好地了解功能和產品,您可以隨時訪問 文檔 部分中的開發人員指南。

支持的文檔格式

您可以對任何文字處理文檔、電子表格、演示文稿、音頻和視頻文件、圖像、PDF、電子書、繪圖等文檔執行操作。下面列出了 GroupDocs API 當前支持的文件格式,希望能滿足您的要求。您可以隨時訪問文檔以了解所有支持的文檔格式或任何類型的指南。

元數據 - SDK 和示例

除了用於雲的元數據編輯REST API之外,GroupDocs還提供開源SDK,因此,可以根據需求進行自定義。開發人員可以使用cURL與GroupDocs.Metadata Cloud API進行交互,也可以使用相關的SDK來加快開發速度。這有助於開發人員不再擔心發出請求和處理響應的低級細節。 GitHub 上提供了下面提到的 SDK 以及代碼示例:

在這個博客中。我使用 Java 代碼來展示如何使用文檔的元數據屬性。此外,我將僅展示提取、添加、刪除和修改元數據的方法之一。您還可以從 文檔 和相關 GitHub 存儲庫中詳細查看 C# 示例和其他方式。

從 Java 或 .NET 文件中提取元數據

該 API 允許您使用不同的選項提取文檔的元數據,其中包括:

  • 整個元數據屬性樹
  • 按指定的標籤、名稱或值

為了給您提供幫助,可以在 GitHub 上獲取運行示例。 我上傳了 groupdocs.app示例,其中顯示了您可以使用 C# 和 Java 提取和創建自己的元數據應用程序。

在 Java 中提取整個元數據屬性樹

設置與雲存儲的連接後,您可以藉助下面提到的幾行代碼提取整個元數據屬性樹。在這裡,我使用 Java SDK for Cloud 提取 Excel 電子表格的屬性樹。您可以使用任何其他可用的 SDK 輕鬆實現此目的。

// Set File Path
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents"+ File.separator +"input.xlsx");
// Set Options to extract the metadata from any file.
ExtractOptions options = new ExtractOptions();
options.setFileInfo(fileInfo);
// Send a Request with options to extract metadata and received the response.
ExtractRequest request = new ExtractRequest(options);
ExtractResult response = apiInstance.extract(request);

用 Java 打印整個元數據樹

// That's it. You have received the whole Metadata Tree. Now you can use it the way you like.
for (MetadataProperty entry : response.getMetadataTree().getInnerPackages().get(0).getPackageProperties()){
	System.out.println("\\n" + entry.getName() + ": " + entry.getValue());
	if (entry.getTags() == null)
		continue;
	// Print Tags
	for (Tag tagItem : entry.getTags()) {
		System.out.println("=== Tag for Property ===");
		System.out.println("Name :" + tagItem.getName());
		System.out.println("Category: " + tagItem.getCategory());
	}
}

輸出

FileFormat: 2
=== Tag for Property ===
Name :FileFormat
Category: Content

MimeType: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
=== Tag for Property ===
Name :FileFormat
Category: Content
 
SpreadsheetFileFormat: 3
=== Tag for Property ===
Name :FileFormat
Category: Content

所有其他不同的元數據提取方法都可以在以下任何資源中查看:

使用 Java 或 .NET 添加元數據

GroupDocs 元數據 REST API 允許您通過以下功能將元數據添加到文檔中:

  • 元數據屬性可能包含不同類型的值,例如字符串、日期時間、整數、雙精度、布爾值
  • 可以通過以下不同方式添加屬性:
    • 按名稱添加元數據屬性:
      • 姓名的一部分
      • 準確的短語
      • 正則表達式匹配
    • 按標籤添加元數據屬性:
      • 精確標籤
      • 可能的標籤名稱

在 Java 中通過精確標記添加元數據屬性

下面,您可以看到通過精確標記添加元數據屬性的源代碼示例:

AddOptions options = new AddOptions();
ArrayList<AddProperty> properties = new ArrayList<AddProperty>();
AddProperty property = new AddProperty();
SearchCriteria searchCriteria = new SearchCriteria();
TagOptions tagOptions = new TagOptions();
// Set Tag name and category
Tag tag = new Tag();
tag.setName("Printed");
tag.setCategory("Time");
// Set Tag
tagOptions.setExactTag(tag);
searchCriteria.setTagOptions(tagOptions);
//Set Date for Value
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
// Setting the Add Property
property.setSearchCriteria(searchCriteria);
property.setValue(dateFormat.format(date));
property.setType("datetime");
properties.add(property);
// Set Properties of AddOptions
options.setProperties(properties);
// Select the document to add metadata property
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/input.docx");
options.setFileInfo(fileInfo);
// Sending the request and fetch response after adding the metadata property
AddRequest request = new AddRequest(options);
AddResult response = apiInstance.add(request);
// Printing the Changes Count and Path of changed file.
System.out.println("Count of changes: " + response.getAddedCount());
System.out.println("Resultant file path: " + response.getPath());

輸出:按標籤添加元數據後

Count of changes: 1
Resultant file path: metadata/add\_metadata/documents/input\_docx/input.docx

添加元數據的所有其他不同方法可以在以下任何資源中查看:

使用 Java 或 .NET 刪除元數據

幾乎使用類似的添加元數據屬性的選項,您還可以從文檔中刪除元數據屬性。

  • 元數據屬性可能包含不同類型的值,例如字符串、日期時間、整數、雙精度、布爾值.
  • 可以通過以下不同方式刪除/移除元數據屬性:
    • 按名稱刪除元數據屬性:
      • 姓名的一部分
      • 準確的短語
      • 匹配正則表達式
    • 按標籤刪除元數據屬性:
      • 精確標籤
      • 可能的標籤名稱

在 Java 中使用正則表達式 (Regex) 刪除元數據

下面,您可以看到用於刪除與提供的正則表達式匹配的元數據屬性的源代碼示例:

// Name Options
NameOptions nameOptions = new NameOptions();
nameOptions.setValue("^\[N\]ame\[A-Z\].\*");
// Match Options
MatchOptions matchOptions = new MatchOptions();
matchOptions.setIsRegex(true);
nameOptions.setMatchOptions(matchOptions);
// Remove Metadata Options and Search Criteria
RemoveOptions options = new RemoveOptions();
SearchCriteria searchCriteria = new SearchCriteria();
// Search Criteria
searchCriteria.setNameOptions(nameOptions);
options.setSearchCriteria(searchCriteria);
// Set fileInfo for the source document
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/input.docx");
options.setFileInfo(fileInfo);
// Send request to remove and receive the response
RemoveRequest request = new RemoveRequest(options);
RemoveResult response = apiInstance.remove(request);
// In response, you can get the path of the updated document with the removed properies.
System.out.println("Count of changes: " + response.getRemovedCount());
System.out.println("Resultant file path: " + response.getPath());

輸出:通過正則表達式刪除元數據後

Count of changes: 1
Resultant file path: metadata/remove\_metadata/documents/input\_docx/input.docx 

可以在以下任意資源中查看刪除元數據的所有其他不同方法:

使用 Java 或 .NET 更新元數據

除了添加、刪除和提取元數據之外,REST API 還允許以不同的方式更新現有元數據屬性。下面我將展示如何通過提供屬性可能的標籤名稱來使用 Java 代碼更新任何文檔的元數據屬性。我使用 Excel 電子表格來更新其創建者元數據標籤。您可以使用 .NET API 在 C# 中實現相同的目的。

使用 Java 按可能的標籤名稱更新元數據

SetOptions options = new SetOptions();
ArrayList<SetProperty> properties = new ArrayList<SetProperty>();
SetProperty property = new SetProperty();
SearchCriteria searchCriteria = new SearchCriteria();
// Set Tag Options and Possible Tag Name
TagOptions tagOptions = new TagOptions();
tagOptions.setPossibleName("creator");
searchCriteria.setTagOptions(tagOptions);
//Set the new Value and Type and then add the property
property.setSearchCriteria(searchCriteria);
property.setNewValue("GroupDocs");
property.setType("string");
properties.add(property);
options.setProperties(properties);
// Select the file to update its metadata properties
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("documents/input.xlsx");
options.setFileInfo(fileInfo);
// Send Request and catch the Response
SetRequest request = new SetRequest(options);
SetResult response = apiInstance.set(request);
// Print the Response Fields
System.out.println("Changes count: " + response.getSetCount());
System.out.println("Resultant file path: " + response.getPath());

輸出:通過可能的標籤名稱修改元數據後

 Count of changes: 1
 Resultant file path: metadata/set\_metadata/documents/input\_xlsx/input.xlsx 

您可以從響應中返回的路徑下載更新的文檔。此外,您可以通過添加和刪除元數據等類似方式更新現有屬性。示例和說明可以在 GroupDocs.Metadata Cloud API 的以下資源中查看。

讓我們談談

這總結了 GroupDocs.Metadata Cloud API 的概述。現在您可以使用上述功能構建您自己的應用程序。如果您在論壇上聯繫我們討論、解決問題或分享您的反饋,我們將非常高興。謝謝。

資源