使用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]...

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/81822.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

arcgis栅格数据之最佳路径分析

1、打开arcmap&#xff0c;加载数据&#xff0c;需要对影像进行监督分类&#xff0c;如下&#xff1a; 这里任选一种监督分类的方法&#xff08;最大似然法&#xff09;&#xff0c;如下&#xff1a; 这里会先生成一个.ecd文件&#xff0c;然后再利用.ecd文件对影像进行分类。如…

linux (platform driver)平台设备驱动匹配方法

Table of Contents 一、匹配函数platform_match 1.1、设备树匹配方法 1.2、id_table匹配方法 1.3、dev-name和platform_driver->drv->name匹配方法 一、匹配函数platform_match 平台设备驱动分为设备层和驱动层&#xff0c;每当有新的设备或者新的设备驱动注册时都要…

“构建高级自定义MVC框架实现CRUD功能的完整指南“

目录 前言1. 导入罐2. 导入工具类3. 配置框架配置文件以及web.xml4. 创建实体类、DAO、Service和Controller5. 配置框架的配置文件6. 页面前端开发 总结 前言 在现代的Web开发中&#xff0c;MVC&#xff08;Model-View-Controller&#xff09;架构模式被广泛应用。它将应用程序…

汽车维修保养记录查询API:实现车辆健康状况一手掌握

在当今的数字化世界中&#xff0c;汽车维修保养记录的查询和管理变得前所未有地简单和便捷。通过API&#xff0c;我们可以轻松地获取车辆的维修和保养记录&#xff0c;从而实现对手中车辆健康状况的实时掌握。 API&#xff08;应用程序接口&#xff09;是进行数据交换和通信的标…

常用 JVM 调优工具

点击下方关注我&#xff0c;然后右上角点击...“设为星标”&#xff0c;就能第一时间收到更新推送啦~~~ JVM 日常调优总结起来就是&#xff1a;首先通过 jps 命令查看当前进程&#xff0c;然后根据 pid 通过 jinfo 命令查看和修改 jvm 参数&#xff0c;通过 jstat 命令查看 cla…

Disruptor-源码解读

前言 Disruptor的高性能&#xff0c;是多种技术结合以及本身架构的结果。本文主要讲源码&#xff0c;涉及到的相关知识点需要读者自行去了解&#xff0c;以下列出&#xff1a; 锁和CAS伪共享和缓存行volatile和内存屏障 原理 添加了中文注释的源码&#xff1a;Disruptor 下…

Databend 开源周报第 105 期

Databend 是一款现代云数仓。专为弹性和高效设计&#xff0c;为您的大规模分析需求保驾护航。自由且开源。即刻体验云服务&#xff1a;https://app.databend.cn 。 Whats On In Databend 探索 Databend 本周新进展&#xff0c;遇到更贴近你心意的 Databend 。 Databend 轻量级…

深入理解负载均衡原理及算法

1. 前言 在互联网早期,网络还不是很发达,上网用户少,流量相对较小,系统架构以单体架构为主。但如今在互联网发达的今天,流量请求动辄百亿、甚至上千亿,单台服务器或者实例已完全不能满足需求,这就有了集群。不论是为了实现高可用还是高性能,都需要用到多台机器来扩展服…

Jupyter Notebook 500 : Internal Server Error

1. 这个问题的根本原因在于&#xff1a; pygments 包 版本过高。 安装pygments 2.6.1 2.jupyter版本如下 如果某个版本有冲突&#xff0c;卸载了重新安装一下就行。 安装命令&#xff1a; pip install pygments 2.6.1 -i https://pypi.tuna.tsinghua.edu.cn/simple 另外…

嘉楠勘智k230开发板上手记录(三)--K230_RVV实战

按照K230_RVV实战.md操作 在k230_sdk目录下运行&#xff0c;Makefile里默认的toolchain路径是在/opt下的&#xff0c;需要拷贝过去 cp -r toolchain /opt/ make rt-smart-apps 进入目录 src/big/rt-smart 运行脚本 source smart-env.sh riscv64 配置环境变量 source smart-e…

git教程(第一次使用)

一、gitee和github区别 二、git使用 下载地址 windows&#xff1a;https://gitforwindows.org/ mac&#xff1a;http://sourceforge.net/projects/git-osx-installer/ 1.git初次运行前的配置 &#xff08;1&#xff09;配置用户信息 git config --global user.name "…

【模型预测控制MPC】使用离散、连续、线性或非线性模型对预测控制进行建模(Matlab代码实现)

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

AP51656 电流采样降压恒流驱动IC RGB PWM深度调光 LED电源驱动

产品描述 AP51656是一款连续电感电流导通模式的降压恒流源&#xff0c;用于驱动一颗或多颗串联LED 输入电压范围从 5 V 到 60V&#xff0c;输出电流 可达 1.5A 。根据不同的输入电压和 外部器件&#xff0c; 可以驱动高达数十瓦的 LED。 内置功率开关&#xff0c;采用电流采样…

我的Python教程:使用Pyecharts画柱状图

Pyecharts是一个用于生成 Echarts 图表的 Python 库。Echarts 是一个基于 JavaScript 的数据可视化库&#xff0c;提供了丰富的图表类型和交互功能。通过 Pyecharts&#xff0c;你可以使用 Python 代码生成各种类型的 Echarts 图表&#xff0c;例如折线图、柱状图、饼图、散点图…

网络安全--mysql中事务锁以及事务隔离解析

一、事务锁 1、个人理解&#xff1a; 专一性和历史性&#xff0c;例如一个男人历史上是花心的&#xff0c;但当他成长后开启begin和update后变的专一了&#xff0c;多项事务也影响不到他了&#xff0c;直到水泥封心&#xff0c;只可被一个人查询在此我们进入正题&#xff1a;…

面试热题(前中序遍历构建树)

给定两个整数数组 preorder 和 inorder &#xff0c;其中 preorder 是二叉树的先序遍历&#xff0c; inorder 是同一棵树的中序遍历&#xff0c;请构造二叉树并返回其根节点。 题目中是给定两个数组&#xff0c;一个是存放这颗树的前序遍历的数组&#xff0c;一个是存放这棵树的…

让三驾马车奔腾:华为如何推动空间智能化发展?

上个月&#xff0c;国务院常务会议审议通过了《关于促进家居消费的若干措施》&#xff0c;其中明确提出了“推动单品智能向全屋智能发展创新培育智能消费”“开展数字家庭建设试点”等推动全屋智能拼配发展的建议与方案。 可以说&#xff0c;以整屋为单位的空间智能品类&#x…

【2.1】Java微服务: Nacos的使用

目录 Nacos介绍 Nacos安装 下载和安装 修改端口 启动 服务注册与发现 导入Nacos管理依赖 导入服务依赖 配置Nacos的服务地址 启动服务&#xff0c;查看已注册的服务 服务分级存储模型 分级存储模型介绍 具体结构 配置实例集群 同集群优先的负载均衡策略 服务权重配置…

安防监控视频汇聚EasyCVR平台的FLV视频流在VLC中无法播放的原因排查

众所周知&#xff0c;TSINGSEE青犀视频汇聚平台EasyCVR可支持多协议方式接入&#xff0c;包括主流标准协议国标GB28181、RTSP/Onvif、RTMP等&#xff0c;以及厂家私有协议与SDK接入&#xff0c;包括海康Ehome、海大宇等设备的SDK等。在视频流的处理与分发上&#xff0c;视频监控…

开发中的花样玩法(前端打工人须知)

一、关于vue使用vant的van-popup&#xff0c;子元素设定固定定位失效问题。 position: fixed; 原因是该组件使用了transform导致&#xff0c;父元素使用了transform会导致子元素在使用固定定位时失效&#xff0c;解决方法就是把要设置固定定位的子元素放在跟组件平级的位置&…