当前位置: 首页 > news >正文

使用Openoffice或LibreOffice实现World、Excel、PPTX在线预览

使用Openoffice或LibreOffice实现World、Excel、PPTX在线预览

  • 预览方案
    • 使用第三方服务
    • 使用前端库
    • 转换格式
  • jodconverter
    • jodconverter概述
    • 主要特性
    • OpenOffice
    • LibreOffice
  • jodconverter的基本使用
    • 添加依赖
    • 配置
    • 创建DocumentConverter实例
    • 上传与转换
    • 预览
    • 启动
    • 上传与预览World
  • 与Spring Boot集成
    • 添加依赖项
    • 配置JodConverter和LibreOffice
    • 启动对比
    • 预览 Excel
    • PPTX预览

预览方案

使用第三方服务

有三方服务提供了在线预览文档的功能,可以将文件上传到这些服务,然后嵌入其提供的预览组件到你的网页中。常用的服务包括 Google Docs、Microsoft Office Online 和 Adobe Document Cloud。

1.调用微软的在线预览功能实现

<iframe src='https://view.officeapps.live.com/op/view.aspx?src='+fileurl width='100%' height='100%' frameborder='1'></iframe>

2.调用google的文档在线预览实现

<iframe :src="https://docs.google.com/viewer?url="+fileurl></iframe>

3.调用XDOC文档预览服务

XDOC文档预览服务:https://view.xdocin.com/

XDOC还可以实现文本、带参数文本、html文本、json文本、公文等在线预览,具体实现方法请看官方文档

注意:预览资源必须是公共可访问的

使用前端库

使用一些前端库来实现文档的在线预览。例如,对于Word文档和Excel文件,可以使用mammoth.js或xlsx.js库来解析和渲染文件内容。对于 PDF 文件,可以使用pdf.js库来渲染和显示PDF内容。

world:https://github.com/mwilliamson/mammoth.js

excel:https://github.com/qax-os/excelizehttps://github.com/tealeg/xlsx

pdf:https://github.com/mozilla/pdf.js

转换格式

将文档转换为特定格式,然后在网页中显示。例如:将Word、Excel、PDF转换成PDF、HTML、图片进行预览。

可以使用jodconverter,它是一个强大的文档转换工具,适用于需要将Office文档转换为其他格式的应用程序。

jodconverter

jodconverter概述

jodconverter是一个开源项目,用于将 Office 文档(如 Word、Excel、PowerPoint 等)转换为其他格式,例如 PDF、HTML、图像等。它基于 Java 平台,并使用 LibreOffice/OpenOffice 作为转换引擎。

jodconverter 提供了简单易用的 API,使开发人员能够在自己的应用程序中集成文档转换功能。它可以与 Java 应用程序一起使用,也可以通过 REST API 进行远程调用。

Github:https://github.com/jodconverter/jodconverter

主要特性

文档转换:jodconverter 可以将各种 Office 文档格式(如 DOCX、XLSX、PPTX 等)转换为其他格式,如 PDF、HTML、图像(PNG、JPEG 等)等。批量转换:你可以使用 jodconverter 批量转换多个文档,提高转换效率。异步转换:jodconverter 支持异步转换,可以在后台进行文档转换,不会阻塞主线程。自定义配置:你可以根据需要配置转换过程中的参数,如输出格式、图像质量、页面大小等。监听器支持:jodconverter 提供了监听器接口,可以在转换过程中监听转换状态和进度。多平台支持:jodconverter 可以在多个平台上运行,包括 Windows、Linux 和 macOS。

OpenOffice

jodconverter依赖于Apache OpenOffice或LibreOffice,在使用jodconverter之前需要先安装二者其一

Apache OpenOffice是一款免费的开源办公软件套件,包含了文本编辑器、电子表格、演示文稿、图形处理和数据库管理等多种功能。它由Apache软件基金会开发和维护,支持跨平台,可以在Windows、Mac和Linux等操作系统上运行。Apache OpenOffice与Microsoft Office相似,可用于创建、编辑和共享各种文档、报告和电子邮件等内容。

openoffice下载:http://www.openoffice.org/download/index.html
在这里插入图片描述
在这里插入图片描述

LibreOffice

jodconverter依赖于Apache OpenOffice或LibreOffice,在使用jodconverter之前需要先安装二者其一

LibreOffice是一款免费的开源办公套件,它包括文本编辑器、电子表格、演示文稿、绘图和数据库管理工具等多个组件,可以用于处理各种常见的办公任务。LibreOffice由The Document Foundation开发,是OpenOffice.org的一个分支,其源代码是完全开放的,并且提供了对多种操作系统的支持,包括Windows、Mac OS X和Linux等。

libreoffice:https://www.libreoffice.org/download/download-libreoffice/

在这里插入图片描述
在这里插入图片描述

jodconverter的基本使用

添加依赖

        <!-- 核心包 --><dependency><groupId>org.jodconverter</groupId><artifactId>jodconverter-core</artifactId><version>4.4.6</version></dependency><!-- 本地支持包 --><dependency><groupId>org.jodconverter</groupId><artifactId>jodconverter-local</artifactId><version>4.4.6</version></dependency>

配置

jodconverter:local:# libreOffice根目录
#    office-home: D:\LibreOffice# OpenOffice安装地址office-home: D:\OpenOffice 4# 同时执行任务的个数,最大进程数max-tasks-per-process: 2# 开启多个进程,每个端口对应一个进程;设置端口号(任意设置)port-numbers: 3000,3001# 一个进程的超时时间process-timeout: 120000

创建DocumentConverter实例

import lombok.extern.slf4j.Slf4j;
import org.jodconverter.core.DocumentConverter;
import org.jodconverter.core.office.InstalledOfficeManagerHolder;
import org.jodconverter.core.office.OfficeException;
import org.jodconverter.core.office.OfficeManager;
import org.jodconverter.core.office.OfficeUtils;
import org.jodconverter.local.LocalConverter;
import org.jodconverter.local.office.LocalOfficeManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Arrays;@Slf4j
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ConverterConfiguration {private LocalOfficeManager officeManager;@Value("${jodconverter.local.office-home}")private String officeHome;@Value("${jodconverter.local.port-numbers}")private String portNumber;@Value("${jodconverter.local.max-tasks-per-process}")private Integer maxTaskPerProcess;@Value("${jodconverter.local.process-timeout}")private Long processTimeout;/*** 启动Office组件进程** @return*/@PostConstructpublic OfficeManager officeManager() {// 多个端口处理String[] portsString = portNumber.split(",");int[] ports = Arrays.stream(portsString).mapToInt(Integer::parseInt).toArray();// 系统判断String os = System.getProperty("os.name").toLowerCase();officeManager = LocalOfficeManager.builder().officeHome(os.contains("windows") ? officeHome : "linuxHome").portNumbers(ports).processTimeout(processTimeout).maxTasksPerProcess(maxTaskPerProcess).install().build();try {officeManager.start();InstalledOfficeManagerHolder.setInstance(officeManager);log.info("office进程启动成功");} catch (OfficeException e) {log.error("启动office组件失败");throw new RuntimeException(e);}return officeManager;}/*** 创建DocumentConverter实例** @return*/@Beanpublic DocumentConverter documentConverter() {log.info("创建DocumentConverter实例");LocalConverter converter = LocalConverter.builder().officeManager(officeManager).build();return converter;}@PreDestroypublic void destroyOfficeManager() {if (null != officeManager && officeManager.isRunning()) {log.info("终止office进程");OfficeUtils.stopQuietly(officeManager);}}}

上传与转换


import org.jodconverter.DocumentConverter;
import org.jodconverter.document.DefaultDocumentFormatRegistry;
import org.jodconverter.office.OfficeException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.UUID;@RestController
public class FileController {/*** 上传与预览的测试目录*/public static String PATH = "D://test//";/***  转换器*/@Autowiredprivate DocumentConverter documentConverter;@GetMapping("/test")public String test() {return "OK";}@PostMapping("/upload")public String handleFileUpload(@RequestParam("file") MultipartFile file) throws OfficeException {if (file.isEmpty()) {return "请选择上传文件";}// 保存上传文件File localFile = new File(PATH + file.getOriginalFilename());try (OutputStream os = new FileOutputStream(localFile)) {os.write(file.getBytes());} catch (IOException e) {e.printStackTrace();}// 转换成pdf的名称String pdfName = UUID.randomUUID().toString().replace("-", "");// 转换成pdf存放路径File pdfFile = new File(PATH + pdfName + ".pdf");// 开始转换documentConverter.convert(localFile).as("doc".equals(DefaultDocumentFormatRegistry.DOC.getExtension()) ? DefaultDocumentFormatRegistry.DOC : DefaultDocumentFormatRegistry.DOCX).to(pdfFile).as(DefaultDocumentFormatRegistry.PDF).execute();// 返回转换后的pdf文件的URLString previewUrl = "http://localhost:8888/preview/" + pdfName;return "<a href='" + previewUrl + "' target='_blank'>Preview</a>";}
}

预览

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;@RestController
public class PreviewController {@GetMapping("/preview/{fileName}")public void showPreview(@PathVariable String fileName, HttpServletResponse response) throws IOException {File file = new File(FileController.PATH + fileName + ".pdf");response.setContentType("application/pdf");response.setHeader("Content-Disposition", "inline; filename=" + fileName);response.setHeader("Content-Length", String.valueOf(file.length()));Files.copy(file.toPath(), response.getOutputStream());}
}

启动

OpenOffice启动日志:

INFO 25076 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
INFO 25076 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
INFO 25076 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
INFO 25076 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
INFO 25076 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
INFO 25076 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
INFO 25076 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.1l  24 Aug 2021]
INFO 25076 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
INFO 25076 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2235 ms
INFO 25076 --- [  restartedMain] c.y.demo.config.ConverterConfiguration   : office进程启动成功
INFO 25076 --- [er-offprocmng-0] o.j.local.office.OfficeDescriptor        : soffice info (from exec path): Product: OpenOffice - Version: ??? - useLongOptionNameGnuStyle: false
INFO 25076 --- [er-offprocmng-1] o.j.local.office.OfficeDescriptor        : soffice info (from exec path): Product: OpenOffice - Version: ??? - useLongOptionNameGnuStyle: false
INFO 25076 --- [  restartedMain] c.y.demo.config.ConverterConfiguration   : 创建DocumentConverter实例
INFO 25076 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
INFO 25076 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
INFO 25076 --- [er-offprocmng-0] o.j.l.office.LocalOfficeProcessManager   : Starting process with --accept 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1;urp;StarOffice.ServiceManager' and profileDir 'C:\Users\Admin\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-3000_tcpNoDelay-1'
INFO 25076 --- [er-offprocmng-1] o.j.l.office.LocalOfficeProcessManager   : Starting process with --accept 'socket,host=127.0.0.1,port=3001,tcpNoDelay=1;urp;StarOffice.ServiceManager' and profileDir 'C:\Users\Admin\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-3001_tcpNoDelay-1'
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
INFO 25076 --- [er-offprocmng-0] o.j.local.office.OfficeConnection        : Connected: 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1'
INFO 25076 --- [er-offprocmng-0] o.j.l.office.LocalOfficeProcessManager   : Started process; pid: 27528
INFO 25076 --- [er-offprocmng-1] o.j.local.office.OfficeConnection        : Connected: 'socket,host=127.0.0.1,port=3001,tcpNoDelay=1'
INFO 25076 --- [er-offprocmng-1] o.j.l.office.LocalOfficeProcessManager   : Started process; pid: 20444
INFO 25076 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
INFO 25076 --- [  restartedMain] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
INFO 25076 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
INFO 25076 --- [  restartedMain] cn.ybzy.demo.Application                 : Started Application in 6.576 seconds (JVM running for 8.362)
INFO 25076 --- [1)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
WARN 25076 --- [1)-192.168.56.1] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
INFO 25076 --- [1)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
INFO 25076 --- [3)-192.168.56.1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 25076 --- [3)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 25076 --- [3)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 9 ms
INFO 25076 --- [ter-poolentry-2] o.j.local.task.LocalConversionTask       : Executing local conversion task [doc -> pdf]...

LibreOffice启动日志:

5728 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
25728 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
5728 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
NFO 5728 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].INFO 5728 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].INFO 5728 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]INFO 5728 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.1l  24 Aug 2021]INFO 5728 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContextINFO 5728 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2260 msINFO 5728 --- [  restartedMain] c.y.demo.config.ConverterConfiguration   : office进程启动成功INFO 5728 --- [er-offprocmng-0] o.j.local.office.OfficeDescriptor        : soffice info (from exec path): Product: LibreOffice - Version: ??? - useLongOptionNameGnuStyle: true
INFO 5728 --- [er-offprocmng-1] o.j.local.office.OfficeDescriptor        : soffice info (from exec path): Product: LibreOffice - Version: ??? - useLongOptionNameGnuStyle: true
INFO 5728 --- [  restartedMain] c.y.demo.config.ConverterConfiguration   : 创建DocumentConverter实例
INFO 5728 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
INFO 5728 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
INFO 5728 --- [er-offprocmng-1] o.j.l.office.LocalOfficeProcessManager   : Starting process with --accept 'socket,host=127.0.0.1,port=3001,tcpNoDelay=1;urp;StarOffice.ServiceManager' and profileDir 'C:\Users\Admin\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-3001_tcpNoDelay-1'
INFO 5728 --- [er-offprocmng-0] o.j.l.office.LocalOfficeProcessManager   : Starting process with --accept 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1;urp;StarOffice.ServiceManager' and profileDir 'C:\Users\Admin\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-3000_tcpNoDelay-1'
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
INFO 5728 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
INFO 5728 --- [  restartedMain] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
INFO 5728 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
INFO 5728 --- [  restartedMain] cn.ybzy.demo.Application                 : Started Application in 6.968 seconds (JVM running for 8.97)
INFO 5728 --- [1)-192.168.56.1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 5728 --- [1)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet' INFO 5728 --- [2)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
WARN 5728 --- [2)-192.168.56.1] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
INFO 5728 --- [1)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 10 ms
INFO 5728 --- [2)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
INFO 5728 --- [er-offprocmng-1] o.j.local.office.OfficeConnection        : Connected: 'socket,host=127.0.0.1,port=3001,tcpNoDelay=1'
INFO 5728 --- [er-offprocmng-1] o.j.l.office.LocalOfficeProcessManager   : Started process; pid: 29060
INFO 5728 --- [er-offprocmng-0] o.j.local.office.OfficeConnection        : Connected: 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1'
INFO 5728 --- [er-offprocmng-0] o.j.l.office.LocalOfficeProcessManager   : Started process; pid: 16476
INFO 5728 --- [ter-poolentry-2] o.j.local.task.LocalConversionTask       : Executing local conversion task [doc -> pdf]...

上传与预览World

在这里插入图片描述

在这里插入图片描述

与Spring Boot集成

添加依赖项

        <!-- 核心包 --><dependency><groupId>org.jodconverter</groupId><artifactId>jodconverter-core</artifactId><version>4.2.2</version></dependency><!-- 本地支持包 --><dependency><groupId>org.jodconverter</groupId><artifactId>jodconverter-local</artifactId><version>4.2.2</version></dependency><!-- springboot支持,包括自动配置类 --><dependency><groupId>org.jodconverter</groupId><artifactId>jodconverter-spring-boot-starter</artifactId><version>4.2.2</version></dependency>

配置JodConverter和LibreOffice

通过在应用程序的配置文件中添加以下属性来配置JodConverter和LibreOffice:

jodconverter:local:enabled: true# libreOffice根目录office-home: D:\LibreOffice# OpenOffice安装地址# office-home: D:\OpenOffice 4# 同时执行任务的个数,最大进程数max-tasks-per-process: 2# 开启多个进程,每个端口对应一个进程;设置端口号(任意设置)port-numbers: 3000# 任务执行的超时时间taskExecutionTimeout: 120000# 任务队列的超时时间taskQueueTimeout: 30000# 一个进程的超时时间process-timeout: 120000

启动对比

使用Openoffice

INFO 17640 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
INFO 17640 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
INFO 17640 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
INFO 17640 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
INFO 17640 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
INFO 17640 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
INFO 17640 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.1l  24 Aug 2021]
INFO 17640 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
INFO 17640 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5223 ms
INFO 17640 --- [  restartedMain] o.j.office.OfficeProcessManager          : Submitting task 'Start' and waiting...
INFO 17640 --- [ProcessThread-0] o.jodconverter.office.OfficeDescriptor   : soffice info (from exec path): Product: OpenOffice - Version: ??? - useLongOptionNameGnuStyle: false
INFO 17640 --- [ProcessThread-0] org.jodconverter.office.OfficeProcess    : Starting process with acceptString 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1;urp;StarOffice.ServiceManager' and profileDir 'C:\Users\Admin\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-3000_tcpNoDelay-1'
INFO 17640 --- [ProcessThread-0] org.jodconverter.office.OfficeProcess    : Started process; pid = 19960
INFO 17640 --- [ProcessThread-0] o.jodconverter.office.OfficeConnection   : Connected: 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1'
INFO 17640 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
INFO 17640 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
INFO 17640 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
INFO 17640 --- [  restartedMain] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
INFO 17640 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
INFO 17640 --- [  restartedMain] cn.ybzy.demo.Application                 : Started Application in 12.67 seconds (JVM running for 16.446)
INFO 17640 --- [2)-192.168.56.1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 17640 --- [2)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 17640 --- [1)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
WARN 17640 --- [1)-192.168.56.1] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
INFO 17640 --- [2)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 16 ms
INFO 17640 --- [1)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
INFO 17640 --- [agerPoolEntry-1] o.jodconverter.task.LocalConversionTask  : Executing local conversion task...

使用LibreOffice

INFO 13756 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8888 (http)
INFO 13756 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
INFO 13756 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
INFO 13756 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
INFO 13756 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
INFO 13756 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
INFO 13756 --- [  restartedMain] o.a.catalina.core.AprLifecycleListener   : OpenSSL successfully initialized [OpenSSL 1.1.1l  24 Aug 2021]
INFO 13756 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
INFO 13756 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2312 ms
INFO 13756 --- [  restartedMain] o.j.office.OfficeProcessManager          : Submitting task 'Start' and waiting...
INFO 13756 --- [ProcessThread-0] o.jodconverter.office.OfficeDescriptor   : soffice info (from exec path): Product: LibreOffice - Version: ??? - useLongOptionNameGnuStyle: true
INFO 13756 --- [ProcessThread-0] org.jodconverter.office.OfficeProcess    : Starting process with acceptString 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1;urp;StarOffice.ServiceManager' and profileDir 'C:\Users\Admin\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-3000_tcpNoDelay-1'
INFO 13756 --- [ProcessThread-0] org.jodconverter.office.OfficeProcess    : Started process; pid = 3216
INFO 13756 --- [ProcessThread-0] o.jodconverter.office.OfficeConnection   : Connected: 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1'
INFO 13756 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
INFO 13756 --- [  restartedMain] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
INFO 13756 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
INFO 13756 --- [  restartedMain] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
INFO 13756 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path ''
INFO 13756 --- [  restartedMain] cn.ybzy.demo.Application                 : Started Application in 21.748 seconds (JVM running for 23.568)
INFO 13756 --- [1)-192.168.56.1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
INFO 13756 --- [1)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
INFO 13756 --- [2)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
WARN 13756 --- [2)-192.168.56.1] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
INFO 13756 --- [1)-192.168.56.1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 10 ms
INFO 13756 --- [2)-192.168.56.1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
INFO 13756 --- [agerPoolEntry-1] o.jodconverter.task.LocalConversionTask  : Executing local conversion task...

经测试发现: 使用Openoffice启动速度更快

预览 Excel

可以将Excel转成PDF或者HTML格式进行预览,通常来说转成HTML格式更好,这里仅作为调试转换成PDF

@RestController
public class FileController {/*** 上传与预览的测试目录*/public static String PATH = "D://test//";@Autowiredprivate DocumentConverter documentConverter;@GetMapping("/test")public String test() {return "OK";}@PostMapping("/upload")public String handleFileUpload(@RequestParam("file") MultipartFile file) throws OfficeException, IOException {if (file.isEmpty()) {return "请选择上传文件";}// 保存上传文件File localFile = new File(PATH + file.getOriginalFilename());FileUtils.writeByteArrayToFile(localFile, file.getBytes());// 转换成pdf的名称String pdfName = UUID.randomUUID().toString().replace("-", "");// 转换成pdf存放路径File pdfFile = new File(PATH + pdfName + ".pdf");// 开始转换documentConverter.convert(localFile).to(pdfFile).execute();// 返回转换后的pdf文件的URLString previewUrl = "http://localhost:8888/preview/" + pdfName;return "<a href='" + previewUrl + "' target='_blank'>Preview</a>";}
}
NFO 24048 --- [er-offprocmng-0] o.j.local.office.OfficeConnection        : Connected: 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1'
INFO 24048 --- [er-offprocmng-0] o.j.l.office.LocalOfficeProcessManager   : Started process; pid: 9896
INFO 24048 --- [ter-poolentry-1] o.j.local.task.LocalConversionTask       : Executing local conversion task [xlsx -> pdf]...

在这里插入图片描述

在这里插入图片描述

PPTX预览

    @PostMapping("/upload")public String handleFileUpload(@RequestParam("file") MultipartFile file) throws OfficeException, IOException {if (file.isEmpty()) {return "请选择上传文件";}// 保存上传文件File localFile = new File(PATH + file.getOriginalFilename());FileUtils.writeByteArrayToFile(localFile, file.getBytes());// 转换成pdf的名称String pdfName = UUID.randomUUID().toString().replace("-", "");// 转换成pdf存放路径File pdfFile = new File(PATH + pdfName + ".pdf");// 开始转换documentConverter.convert(localFile).to(pdfFile).execute();// 返回转换后的pdf文件的URLString previewUrl = "http://localhost:8888/preview/" + pdfName;return previewUrl;}

在这里插入图片描述

INFO 24048 --- [er-offprocmng-0] o.j.local.office.OfficeConnection        : Connected: 'socket,host=127.0.0.1,port=3000,tcpNoDelay=1'
INFO 24048 --- [er-offprocmng-0] o.j.l.office.LocalOfficeProcessManager   : Started process; pid: 16724
INFO 24048 --- [ter-poolentry-1] o.j.local.task.LocalConversionTask       : Executing local conversion task [pptx -> pdf]...

相关文章:

使用Openoffice或LibreOffice实现World、Excel、PPTX在线预览

使用Openoffice或LibreOffice实现World、Excel、PPTX在线预览 预览方案使用第三方服务使用前端库转换格式 jodconverterjodconverter概述主要特性OpenOfficeLibreOffice jodconverter的基本使用添加依赖配置创建DocumentConverter实例上传与转换预览启动上传与预览World 与Spri…...

20天学会rust(三)没有object的rust怎么面向对象?

面向对象我们都很熟悉&#xff0c;可以说它是一种软件开发最重要的编程范式之一&#xff0c;它将程序中的数据和操作数据的方法组织成对象。面向对象有几个重要特性&#xff1a; 封装、继承和多态&#xff0c;基于这些特性带来了在可重用性、可维护性、扩展性、可靠性的优点。 …...

整数规划——第三章 全单模矩阵

整数规划——第三章 全单模矩阵 若线性规划问题的约束矩阵为全单模矩阵&#xff0c;则该问题可行域的顶点都是整数点&#xff0c;从而线性规划与整数规划的最优解相同。 3.1 全单模性与最优性 考虑线性整数规划问题&#xff1a; (IP) min ⁡ c T x , s . t . A x ≤ b , x …...

数据结构和算法

数据结构和算法目录表 CCJava线性结构 1. 数组、单链表和双链表 2. Linux内核中双向链表的经典实现 数组、单链表和双链表 数组、单链表和双链表 栈 栈 栈 队列 队列 队列树形结构 二叉查找树 二叉查找树 二叉查找树 AVL树 AVL树 AVL树 伸展树 伸展树 伸展树 1. 红黑树(一)之…...

[Vulnhub] matrix-breakout-2-morpheus

目录 <1> 信息收集 <2> getshell <3> Privilege Escalation&#xff08;提权&#xff09; <1> 信息收集 nmap -sP 192.168.236.0/24 扫描一下靶机ip 靶机ip: 192.168.236.154 nmap -A -p 1-65535 192.168.236.154 扫描一下靶机开放哪些服务 开放…...

JDK, JRE和JVM之间的区别和联系

JDK, JRE和JVM是与Java编程语言相关的三个重要的概念&#xff0c;它们分别代表Java Development Kit&#xff08;Java开发工具包&#xff09;、Java Runtime Environment&#xff08;Java运行时环境&#xff09;和Java虚拟机&#xff08;Java Virtual Machine&#xff09;。它们…...

mac电脑访问windows共享文件夹连接不上(设置445端口)

前提&#xff1a;首先需要保证mac和windows都在同一局域网内&#xff0c;如果不在肯定是连不上的&#xff0c;就不用往下看了。 事情是这样的&#xff0c;公司入职发了mac电脑&#xff0c;但是我是window重度用户&#xff0c;在折腾mac的过程中&#xff0c;有许多文件需要从wi…...

metersphere性能压测执行过程

(1) 首先在controller层&#xff0c;通过RunTestPlanRequest接收请求参数 PostMapping("/run")public String run(RequestBody RunTestPlanRequest request) (2) 在PerformanceTestService中的run中进行具体的逻辑处理&#xff0c; 首先根据请求中ID来获取库中存储…...

揭秘Word高级技巧:事半功倍的文字处理策略

Microsoft Word是一款广泛使用的文字处理软件&#xff0c;几乎每个人都有使用过它的经历。但是&#xff0c;你是否知道Word中隐藏着许多高级技巧和功能&#xff0c;可以帮助你事半功倍地处理文字&#xff1f;在本文中&#xff0c;我们将揭秘一些Word的高级技巧&#xff0c;让你…...

06-1_Qt 5.9 C++开发指南_对话框与多窗体设计_标准对话框

在一个完整的应用程序设计中&#xff0c;不可避免地会涉及多个窗体、对话框的设计和调用&#xff0c;如何设计和调用这些对话框和窗体是搞清楚一个庞大的应用程序设计的基础。本章将介绍对话框和多窗体设计、调用方式、数据传递等问题&#xff0c;主要包括以下几点。 Qt 提供的…...

模拟实现消息队列项目(系列7) -- 实现BrokerServer

目录 前言 1. 创建BrokerServer类 1.1 启动服务器 1.2 停止服务器 1.3 处理一个客户端的连接 1.3.1 解析请求得到Request对象 1.3.2 根据请求计算响应 1.3.3 将响应写回给客户端 1.3.4 遍历Session的哈希表,把断开的Socket对象的键值对进行删除 2. 处理订阅消息请求详解(补充) …...

vscode插件不能搜索安装

1 现象 vscode搜索自己的插件&#xff0c;报错&#xff1a; Error while fetching extensions. HXR failed2 原因 之前用vscode开发golang语言&#xff0c;设置了proxy代理&#xff0c;所以导致错误&#xff0c;删除即可 重启vscode 3 结果...

路由器工作原理(第二十九课)

路由器工作原理(第二十九课) 一图胜过千言 1) 路由:数据从一个网络到另外一个网络之间转发数据包的过程称为路由 2) 路由器:连接不同网络,实现不同网段之间的通信 3)路由表:路由器选择数据的传输路径的依据 原始的路由表 Destination/Mask Proto Pre Cost …...

linux log 日志

/* author: hjjdebug * date: 2023年 08月 08日 星期二 13:18:08 CST * descriptor: linux log 日志 * destinator: 搞清linux 下log 日志 * 下面代码编译通过即可运行 */ #include <stdio.h> #include <syslog.h> int main(void) { // 打开系统日志, 可…...

uniapp获取当前页面高度

设置动态高度:style"{height: pageHeightpx}" <view class"uni-content" :style"{height: pageHeightpx}" >... </view>获取当前页面高度&#xff1a; onLoad() {// 获取当前窗口高度this.pageHeight uni.getSystemInfoSync().wi…...

Java课题笔记~ Spring 集成 MyBatis

Spring 集成 MyBatis 将 MyBatis 与 Spring 进行整合&#xff0c;主要解决的问题就是将 SqlSessionFactory 对象交由 Spring 来管理。所以该整合&#xff0c;只需要将 SqlSessionFactory 的对象生成器SqlSessionFactoryBean 注册在 Spring 容器中&#xff0c;再将其注入给 Dao…...

分布式系统理论基础

文章目录 介绍目标 正文CAPConsistencyAvailabilityPartition tolerance BASEBasically AvailableSoft StateEventually Consistent ACIDatomicityconsistencyisolationdurability 参考文档 介绍 分布式系统面临的场景往往是众口难调&#xff0c;“这也要&#xff0c;那也要”…...

mfc 编辑框限制

DoDataExchange由框架调用&#xff0c;作用是交互并且验证对话框数据&#xff0c;主要由(DDX) 和 (DDV)宏实现。 永远不要直接调用这个函数&#xff0c;而是通过UpdateData(TRUE/FALSE)实现控件与变量之间值的传递。 当然你也可以不使用DoDataExchange而完成控件与变量之间值…...

web基础与tomcat环境部署

一. 简述静态网页和动态网页的区别。 请求响应信息&#xff0c;发给客户端进行处理&#xff0c;由浏览器进行解析&#xff0c;显示的页面称为静态页面。处理文件类型如.html、jpg、.gif、.mp4、.swf、.avi、.wmv、.flv等 请求响应信息&#xff0c;发给事务端进行处理&#xff0…...

Go 变量

在Go中&#xff0c;有不同的变量类型&#xff0c;例如&#xff1a; int 存储整数&#xff08;整数&#xff09;&#xff0c;例如123或-123float32 存储浮点数字&#xff0c;带小数&#xff0c;例如19.99或-19.99string - 存储文本&#xff0c;例如“ Hello World”。字符串值用…...

【雷达通信】非相干多视处理(CSA)(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…...

73. 矩阵置零

题目链接&#xff1a;力扣 解题思路&#xff1a; 方法一&#xff1a;比较容易想到的方向&#xff0c;使用两个数组row和col保存有0的行或者列&#xff0c;然后将有0的那一行或那一列的所有元素都设置为0 AC代码 class Solution {public void setZeroes(int[][] matrix) {in…...

‘大数据技术与应用’和‘数据科学与大数据技术’有什么区别

一、侧重点不同 ‘大数据技术与应用’主要侧重于大数据的存储、处理和分析技术、包括数据挖掘、机器学习、数据仓库、分布式计算等方面的研究&#xff0c;旨在开发大数据相关的应用程序和系统&#xff0c;以满足商业和企业的需求。 ‘数据科学与大数据技术’则更加注重数据本…...

没有jsoup,rust怎么解析html呢?

在 Rust 中&#xff0c;你可以使用各种库来解析网页内容。一个常用的库是 reqwest &#xff0c;它提供了一个简单的方式来发送 HTTP 请求并获取网页内容。另外&#xff0c;你可以使用 scraper 或 select 等库来解析 HTML 或 XML 格式的网页内容。 下面是一个使用 reqwest 和 sc…...

【C高级】Day4 shell脚本 排序

1. 整理思维导图 2. 写一个函数&#xff0c;获取用户的uid和gid并使用变量接收 #!/bin/bash function getid() {uidid -ugidid -g }getid echo "uid$uid" echo "gid$gid"3. 整理冒泡排序、选择排序和快速排序的代码 #include <myhead.h>void Inp…...

大模型开发(十六):从0到1构建一个高度自动化的AI项目开发流程(中)

全文共1w余字&#xff0c;预计阅读时间约40~60分钟 | 满满干货(附代码)&#xff0c;建议收藏&#xff01; 本文目标&#xff1a;通过LtM提示流程实现自动构建符合要求的函数&#xff0c;并通过实验逐步完整测试code_generate函数功能。 代码下载点这里 一、介绍 此篇文章为…...

【深入了解pytorch】PyTorch强化学习:强化学习的基本概念、马尔可夫决策过程(MDP)和常见的强化学习算法

【深入了解pytorch】PyTorch强化学习:强化学习的基本概念、马尔可夫决策过程(MDP)和常见的强化学习算法 PyTorch强化学习:介绍强化学习的基本概念、马尔可夫决策过程(MDP)和常见的强化学习算法引言强化学习的基本概念状态(State)动作(Action)奖励(Reward)策略(Pol…...

尚硅谷张天禹Vue2+Vue3笔记(待续)

简介 什么是Vue&#xff1f; 一套用于构建用户界面的渐进式JavaScript框架。将数据转变成用户可看到的界面。 什么是渐进式&#xff1f; Vue可以自底向上逐层的应用 简单应用:只需一个轻量小巧的核心库 复杂应用:可以引入各式各样的Vue插件 Vue的特点是什么&#xff1f; 1.采…...

深度学习(35)—— StarGAN(2)

深度学习&#xff08;34&#xff09;—— StarGAN&#xff08;2&#xff09; 完整项目在这里&#xff1a;欢迎造访 文章目录 深度学习&#xff08;34&#xff09;—— StarGAN&#xff08;2&#xff09;1. build model&#xff08;1&#xff09;generator&#xff08;2&#…...

连续四年入选!三项荣耀!博云科技强势上榜Gartner ICT技术成熟度曲线

日&#xff0c;全球知名咨询公司Gartner发布了2023年度的《中国ICT技术成熟度曲线》&#xff08;《Hype Cycle for ICT in China, 2023》&#xff0c;以下简称“报告”&#xff09;。令人瞩目的是&#xff0c;博云科技在报告中荣获三项殊荣&#xff0c;入选云原生计算&#xff…...

网站定制论文1500字左右/推广公司产品

问题&#xff1a;我在视图画的图象或者文字&#xff0c;当窗口改变后为什么不见了&#xff1f;OnDraw()和OnPaint()两个都是解决上面的问题&#xff0c;有什么不同&#xff1f; 答&#xff1a;OnDraw()和OnPaint()好象兄弟俩&#xff0c;因为它们的工作类似。至于不见了的问题…...

文山 网站建设 滇icp/各国足球世界排名

PHP 函数索引(共有 967 个函数)Abs: 取得绝对值。Acos: 取得反余弦值。ada_afetch: 取得数据库的返回列。ada_autocommit: 开关自动改动功能。ada_close: 关闭 Adabas D 链接。ada_commit: 改动 Adabas D 数据库。ada_connect: 链接至 Adabas D 数据库。ada_exec: 执行 SQL 指令…...

外贸网站模板哪里下载/百度搜索引擎下载

作为 Nacos 5W1H 的系列文章&#xff0c;本文将围绕“Where”&#xff0c;讲述 Nacos 配置管理的三个典型的应用场景&#xff1a; 数据库连接信息限流阈值和降级开关流量的动态调度上一篇&#xff1a;Nacos帮我解决了什么问题&#xff1f; 数据库连接信息 曾经有朋友跟我聊过…...

如何编辑网页/郑州seo技术博客

创建&#xff08;进入&#xff09;VLAN10[SwitchA]vlan 102. 将E0/1加入到VLAN10[SwitchA-vlan10]port Ethernet 0/1 Ethernet 0/2 GigabitEthernet 1/13. 配置VLAN10内的端口隔离[SwitchA-vlan10]port-isolate enable4. 将连接服务器的端口配置为隔离端口的上行端口[SwitchA]i…...

建一个动物网站怎么做/百度网盟推广官方网站

Minimum Vagrant Version 可以在Vagrantfile中指定一组vagrant版本需求&#xff0c;以强制人们使用带有Vagrantfile文件的vagrant特定版本。这可以帮助解决使用带有Vagrantfile的旧版本或新版本时可能出现的兼容性问题。 vagrant版本要求应该在Vagrantfile文件的顶部使用 Vagra…...

动态网页文件/网站优化课程

<script languagejavascript> window.onbeforeunload onbeforeunload_handler; window.onunload onunload_handler; //准备去加载 function onbeforeunload_handler(){ var warning"确认退出?"; return warning; } //加载回来准备更换页…...