java实现pptx转html在线预览

在这里插入图片描述

由于ppt中不能插入视频资源文件,但是因公司要求,在pptx中插入视频资源文件,用户将上传pptx在页面预览,因此只能是将视频插入到pptx中,然后将pptx再转换成html在浏览器进行播放,唉,公司的脑回路没办法理解,只能服从……

  1. pom.xml引入依赖
<dependencies>
	<dependency>
		<groupId>e-iceblue</groupId>
		<artifactId>spire.presentation</artifactId>
		<version>8.3.2</version>
		<scope>system</scope>
		<systemPath>${basedir}/src/main/resources/lib/spire.presentation-8.3.2.jar</systemPath>
	</dependency>
</dependencies>
<repositories>
		<repository>
			<id>com.e-iceblue</id>
			<name>e-iceblue</name>
			<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
		</repository>
</repositories>
<plugin>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<configuration>
		<!--includeSystemScope一定要添加,或者打成jar包会报错(java.lang.NoClassDefFoundError: com/spire/presentation/Presentation) -->
	    <includeSystemScope>true</includeSystemScope>
		<!-- 指定该Main Class为全局的唯一入口 -->
		<mainClass>com.SoftUdiskApplication</mainClass>
		<layout>JAR</layout>
	</configuration>
</plugin>	

在这里插入图片描述

  1. 后端实现代码
package com.client.util;

import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;

/**
 * @author:
 * @creattime:2023-03-31 11:21
 */
public class PPTtoHTMLUtil {
    
    

    public static void main(String[] args)throws Exception {
    
    
        //创建Presentation类的对象
        Presentation ppt = new Presentation();
        //加载幻灯片文档
        ppt.loadFromFile("E:/test/123.pptx");
        //保存为HTML格式文档到指定路径
        ppt.saveToFile("E:/test/FileToHtml.html", FileFormat.HTML)
        ppt.dispose();
    }

    /**
     * pptx转换为html
     * @param pptxfile:pptx文件绝对路径
     * @param htmlfile:生成的html文件绝对路径
     * @return
     */
    public static boolean covertpptxToHtml(String pptxfile,String htmlfile){
    
    
        boolean result=false;
        try {
    
    
            //创建Presentation类的对象
            Presentation ppt = new Presentation();
            //加载幻灯片文档
            ppt.loadFromFile(pptxfile);
            //保存为HTML格式文档到指定路径
            ppt.saveToFile(htmlfile, FileFormat.HTML);
            ppt.dispose();
            result=true;
        }catch (Exception e){
    
    
            e.printStackTrace();
            result=false;
        }
        return result;
    }
}

3.效果图
在这里插入图片描述
4.spire.presentation-8.3.2.jar下载流程
①https://repo.e-iceblue.cn/repository/maven-public/
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

注意:一定不能低于此版本,否则报各种错,本人就引了个低版本,调试到差点吐血哇

猜你喜欢

转载自blog.csdn.net/weixin_44975322/article/details/130131974
今日推荐