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

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

使用Apache POI 。

您可以使用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(); } } 

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)); }