HTML转PPT

在 PowerPoint 中嵌入 HTML |在线将 HTML 转换为 PPT

我们将讨论如何使用 Java SDK 将网页插入 PowerPoint 的细节。我们确实了解 PowerPoint 到 HTML 是我们需要将 PPT 导出到 HTML 以便我们可以在 Web 浏览器中查看文件的流行场景之一。但与此同时,我们可能有一个现有的 PowerPoint,我们可能需要在 PowerPoint 中嵌入 HTML,或者出于演示目的,我们有兴趣将 HTML 转换为 PPT。

PowerPoint 转换 SDK

我们将使用 Aspose.Slides Cloud SDK for Java 进行转换。它是一个 REST API,提供创建、编辑 PowerPoint 文件并将其转换为 HTMLPDFXPSJPG 和各种其他 [Supported File] 的功能格式]7。同时,它还提供了将HTML保存为PPT的功能。现在请在您的 Maven 构建项目的 pom.xml 中添加以下详细信息,以便将 SDK 引用添加到您的项目中。

<repositories>
 <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>http://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>
<dependencies>
 <dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-slides-cloud</artifactId>
    <version>22.4.0</version>
 </dependency>
</dependencies>

安装后,如果您没有现有的 Cloud dashboard 帐户,请访问 Aspose.Cloud dashboard 创建一个。如果您有 GitHub 或 Google 帐户,只需注册并获取您的客户凭据。

使用 Java 在 PowerPoint 中嵌入 HTML

本节介绍如何阅读网页并将其插入到 PowerPoint 演示文稿中。请按照以下指定的步骤完成要求。操作成功后,生成的文件将存储在云存储中。

  • 创建 SlidesApi 实例,同时提供客户端凭据作为参数
  • 现在创建一个 StringBuilder 的实例
  • 下一步是将 HTML 文件内容读入 BufferedReader 对象
  • 由于 API 期望输入的 HTML 是字符串格式,因此我们需要使用 contentBuilder.toString(…) 方法将加载的 HTML 内容转换为字符串格式
  • 最后,调用 importFromHtml(..) 方法在 PowerPoint 中嵌入 HTML。
try
    {
    // 从 https://dashboard.aspose.cloud/ 获取 ClientID 和 ClientSecret
    String clientId = "bbf94a2c-6d7e-4020-b4d2-b9809741374e";
    String clientSecret = "1c9379bb7d701c26cc87e741a29987bb";

    // 创建 SlidesApi 的实例
    SlidesApi slidesApi = new SlidesApi(clientId,clientSecret);

    // 创建 StringBuilder 对象
    StringBuilder contentBuilder = new StringBuilder();
    try {
        // 读取输入 HTML 文件的内容
        BufferedReader in = new BufferedReader(new FileReader("c://Users/Downloads/test.html"));
        String str;
        while ((str = in.readLine()) != null) {
            contentBuilder.append(str);
        }
        in.close();
    } catch (IOException e) {
    }
        
    // 将加载的 HTML 内容转换为 String 实例
    String content = contentBuilder.toString();
        
    // 调用方法将网页插入 PowerPoint
    slidesApi.importFromHtml("Resultant.ppt",content, "", "", "Internal");

    // 打印成功信息
    System.out.println("Sucessfully completed embedding html in powerpoint !");
    }catch(Exception ex)
    {
        System.out.println(ex.getStackTrace());
    }
在 PowerPoint 中嵌入 HTML

图片 1:- 在 PowerPoint 预览中嵌入 HTML。

请访问以下链接下载输入 HtmlTemplate.htmlResultant.ppt

请注意,如果 PPT 文件已经存在于云存储中,那么 API 将插入网页到 PowerPoint 中

使用 cURL 命令从 HTML 到 PPT

现在我们将讨论使用 cURL 命令将 HTML 转换为 PPT。因此,第一步是根据您的客户端凭据生成 JWT 访问令牌。

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

生成 JWT 令牌后,我们可以执行以下命令将提供的 HTML 转换为 PPT 格式并将生成的 PowerPoint 保存在云存储中。

curl -v -X POST "https://api.aspose.cloud/v3.0/slides/Resultant.ppt/fromHtml" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "<!DOCTYPE html><html><body><h1 style=\"color:blue;\">This is a heading</h1><p style=\"color:red;\">This is a paragraph.</body></html>"
在 powerpoint 中嵌入 html

在 PowerPoint 预览中嵌入 HTML

在上图中,您可能会注意到我们在 powerpoint(云存储中现有的 PPT)中嵌入了 html。

结论

在本文中,我们了解了使用 Java 代码片段在 PowerPoint 中嵌入 HTML 的详细信息,以及如何使用 cURL 命令将网页插入到 PowerPoint 中。您已经观察到,只需很少的代码行,整个转换过程就完成了,并且生成了最终的 PPT(同时保持完全保真度)。如果您有兴趣修改 SDK 代码库,可以从 GitHub 下载它,因为它是根据 MIT 许可发布的。尽管如此,如果您在 PowerPoint 中嵌入 HTML 时遇到任何问题,或者您有任何进一步的疑问,请随时通过免费技术支持论坛 与我们联系。

相关文章

我们强烈建议访问以下链接以了解: