使用 Java REST API 在 PowerPoint 中显示文档属性

本文指导如何使用 Java REST API 显示 PowerPoint 中的文档属性。您将学习如何使用基于 Java 的云 SDK 通过 Java REST 接口在 PowerPoint 中显示文档属性。它还将共享逻辑以仅显示所需的属性。

先决条件

使用 Java 低代码 API 在 PowerPoint 中显示文档属性的步骤

  1. 通过使用客户端 ID 和密钥创建 SlidesApi 对象来设置环境以获取属性
  2. 定义演示文稿的名称并将其上传到云存储以供进一步处理
  3. Fetch 上传的演示文稿中的属性集合
  4. 遍历集合中的所有属性
  5. 使用名称/值对显示每个或选定的属性

这些步骤描述如何使用 Java RESTful 服务在 PowerPoint 中显示文档属性。使用客户端 ID 和密钥创建 SlidesApi 对象,将目标演示文稿上传到云存储,获取属性集合,然后迭代该集合以显示属性。

使用 Java REST API 在 PowerPoint 中获取文档属性的代码

import com.aspose.slides.ApiException;
import com.aspose.slides.api.SlidesApi;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class Example_DisplayDocumentPropertiesForPresentation {
protected static SlidesApi presentationApi;
public Example_DisplayDocumentPropertiesForPresentation() {
if (presentationApi == null) {
presentationApi = new SlidesApi("appSid", "appKey");
}
}
public void SplitPresentation() throws ApiException, IOException {
String localPath = "/home/downloads/";
String fileName = "TestPresentation.pptx";
String storageFolderName = "TempTests";
presentationApi.uploadFile(storageFolderName+"/"+fileName, readFileToByteArray(storageFolderName+localPath + fileName),null);
// Fetch metadata
var metadata = presentationApi.getDocumentProperties(fileName, null, storageFolderName, null);
// Print the presentation properties
for (var property : metadata.getList())
{
System.out.println(property.getName()+" : " +property.getName());
}
System.out.println("Presentation Document properties reading completed");
}
public static byte[] readFileToByteArray(String filePath) throws IOException {
Path path = new File(filePath).toPath();
return Files.readAllBytes(path);
}
}

此代码演示了在 PowerPoint* 演示文稿中显示*文档属性的过程。您可以根据名称/值对中的属性名称来过滤表示属性。如果演示文稿已存在于服务器存储中,您可以跳过上传步骤。

本文教我们如何获取演示文稿属性。要从演示文稿中提取图片,请参阅文章 使用 Java REST API 从 PowerPoint 中提取图片

 简体中文