使用 Java 将文件 .pptx 转换为 .ppt

发布于 2024-11-13 11:47:05 字数 48 浏览 1 评论 0原文

我想知道是否有人知道一种使用 Java 将 .pptx 转换为 .ppt 的方法?

I was wondering if someone knows a way to convert .pptx to .ppt progamatically using Java?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扛刀软妹 2024-11-20 11:47:05

可以使用openoffice进行转换。您必须正确配置 eclipse/netbeans。您还需要 jodconverter 插件。
哦,记得以聆听模式打开OO

package openofficeconv;
import java.io.File;
import java.net.ConnectException;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.*;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;

public class PowerpointConverter{

public static void main(String[] args) {

    File inputFile = new File("j.pptx");
    File outputFile = new File("j.pdf");

    // connect to an OpenOffice.org instance running on port 8100
    OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
    try {
        connection.connect();
    } catch (ConnectException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // convert
    DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
    converter.convert(inputFile, outputFile);

    // close the connection
    connection.disconnect();
}
}

You can use openoffice for conversion. You have to configure eclipse/netbeans properly. You need jodconverter plugin, too.
oh, and remember to open OO in listening mode

package openofficeconv;
import java.io.File;
import java.net.ConnectException;

import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.*;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;

public class PowerpointConverter{

public static void main(String[] args) {

    File inputFile = new File("j.pptx");
    File outputFile = new File("j.pdf");

    // connect to an OpenOffice.org instance running on port 8100
    OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
    try {
        connection.connect();
    } catch (ConnectException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // convert
    DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
    converter.convert(inputFile, outputFile);

    // close the connection
    connection.disconnect();
}
}
聆听风音 2024-11-20 11:47:05

Aspose Slides 是我唯一的库看过就懂pptx。它不是免费的,但它可能有能力进行转换。 Apache POI 是一个免费的 ppt Java 库,但上次我检查它不支持 pptx。

更新:这是我使用 Aspose 提取图像的方法。一旦获得 png 文件,您应该能够使用其他工具构建 PDF。我需要明确大小的图像 - 你也许可以将其获取为原始大小:

Dimension small = new Dimension(160, 120);
Dimension medium = new Dimension(200,150);
Dimension large = new Dimension(400,300);

for (Slide slide : presentation.getSlides()) {
  String path = FileService.getUploadPath() + slide.getPath();
  com.aspose.slides.Slide pptSlide = ppt.getSlideByPosition(slide.getSequence());
  ImageIO.write(pptSlide.getThumbnail(1, 1), "png", new File(path));

  path = FileService.getUploadPath() + slide.getSmallPath();
  ImageIO.write(pptSlide.getThumbnail(small), "png", new File(path));

  path = FileService.getUploadPath() + slide.getMediumPath();
  ImageIO.write(pptSlide.getThumbnail(medium), "png", new File(path));

  path = FileService.getUploadPath() + slide.getLargePath();
  ImageIO.write(pptSlide.getThumbnail(large), "png", new File(path));
}

Aspose Slides is the only library I've seen that understands pptx. It's not free but it would probably have the ability to do the conversion. Apache POI is a free ppt Java library but last I checked it didn't support pptx.

Update: here's how I extracted images using Aspose. Once you have png files, you should be able to build a PDF using other tools. I needed explicitly sized images - you may be able to just get it as the native size:

Dimension small = new Dimension(160, 120);
Dimension medium = new Dimension(200,150);
Dimension large = new Dimension(400,300);

for (Slide slide : presentation.getSlides()) {
  String path = FileService.getUploadPath() + slide.getPath();
  com.aspose.slides.Slide pptSlide = ppt.getSlideByPosition(slide.getSequence());
  ImageIO.write(pptSlide.getThumbnail(1, 1), "png", new File(path));

  path = FileService.getUploadPath() + slide.getSmallPath();
  ImageIO.write(pptSlide.getThumbnail(small), "png", new File(path));

  path = FileService.getUploadPath() + slide.getMediumPath();
  ImageIO.write(pptSlide.getThumbnail(medium), "png", new File(path));

  path = FileService.getUploadPath() + slide.getLargePath();
  ImageIO.write(pptSlide.getThumbnail(large), "png", new File(path));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文