Java converts PPT slides to HTML

This article uses Java program code as an example to show how to convert PPT slide documents into HTML files through format conversion. The PPT slides here can be in formats such as .ppt/.pptx/.pps/.ppsx/.potx.

Code realization idea : [Load PPT slide file]-[Save as target file format HTML]. The code is relatively simple.

When loading PPT files, you can use the following methods to load PPT files in different formats, as shown in the figure:

About jar import : Before editing the code, import the free spire.presentation.jar file into the Java program, as shown in the figure:

Note that the jar package imported here is the free version.

Java code:

import com.spire.presentation.* ; 

public  class PPTtoHTML {
     public  static  void main(String[] args) throws Exception {
         // Create Presentation object 
        Presentation ppt = new Presentation(); 

        // Load sample document 
        ppt.loadFromFile("sample .pptx" );
         // ppt.loadFromFile("test.pptx","123456"); // Load the encrypted PPT file
         // ppt.loadFromFile("sample.pps",FileFormat.PPS); // Load specified Format PPT file 

        // Save as HTML format document 
        ppt.saveToFile("ToHtml.html", FileFormat.HTML);

Execute the program to generate HTML files. The file path in the above code is the IDEA project folder path, namely C:\Users\Administrator\IdeaProjects\Conversion_PPT\ToHtml.html. You can view the generated HTML file under this path, and the file path can also be customized to other paths.

Conversion result:

PPT document:

HTML document:


This article is reprinted from:

Leave a Reply