在 Java 中将 PDF 转换为 PowerPoint

Aspose.PDF for Java 支持将 PDF 页面导出为可编辑的 PowerPoint 演示文稿,并提供幻灯片渲染选项。使用 PptxSaveOptions 来控制 PDF 页面映射到 PowerPoint 幻灯片的方式。

转换 PDF 为 PPTX

当 PDF 文档应导出为标准 PowerPoint 演示文稿时使用此示例。

  1. 使用 Document 实例打开源 PDF。
  2. 创建默认 PptxSaveOptions 用于可编辑的 PowerPoint 导出。
  3. 调用 document.save(outputFile.toString(), saveOptions) 因此 PDF 页面被序列化为 a .pptx 演示。
  4. 保存已转换的 PPTX 文件。
public static void convertPdfToPptx(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        PptxSaveOptions saveOptions = new PptxSaveOptions();
        document.save(outputFile.toString(), saveOptions);
    }
    System.out.println(inputFile + " converted into " + outputFile);
}

将 PDF 转换为 PPTX,幻灯片作为图像

当每个 PDF 页面应转换为基于图像的 PowerPoint 幻灯片时,请使用此示例。

  1. 使用 Document 实例打开源 PDF。
  2. 创建 PptxSaveOptions 并启用 setSlidesAsImages(true)。
  3. 调用 document.save(outputFile.toString(), saveOptions) 因此,每个 PDF 页面在演示文稿中被渲染为基于图像的幻灯片。
  4. 保存生成的 PPTX 文件。
public static void convertPdfToPptxSlidesAsImages(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        PptxSaveOptions saveOptions = new PptxSaveOptions();
        saveOptions.setSlidesAsImages(true);
        document.save(outputFile.toString(), saveOptions);
    }
    System.out.println(inputFile + " converted into " + outputFile);
}

将 PDF 转换为 PPTX,使用自定义图像分辨率

当在 PDF 转 PPTX 导出过程中需要控制幻灯片图像质量时,请使用此示例。

  1. 使用 Document 实例打开源 PDF。
  2. 创建 PptxSaveOptions 并设置 setImageResolution(300) 以获得更高的幻灯片图像保真度。
  3. 调用 document.save(outputFile.toString(), saveOptions) 因此,光栅化的幻灯片内容会以请求的分辨率生成。
  4. 保存输出的演示文稿。
public static void convertPdfToPptxImageResolution(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        PptxSaveOptions saveOptions = new PptxSaveOptions();
        saveOptions.setImageResolution(300);
        document.save(outputFile.toString(), saveOptions);
    }
    System.out.println(inputFile + " converted into " + outputFile);
}