OpenOffice实现word文档在线预览
林中微光
共 4280字,需浏览 9分钟
· 2021-11-21
linux下安装openoffice
1、解压压缩包
tar -zxvf Apache_OpenOffice_4.1.9_Linux_x86-64_install-rpm_zh-CN.tar.gz
tar -zxvf Apache_OpenOffice_4.1.9_Linux_x86-64_langpack-rpm_zh-CN.tar.gz
2、软件安装
cd zh-CN/RPMS/
rpm -ivh *.rpm
cd desktop-integration
rpm -ivh openoffice4.1.9-redhat-menus-4.1.9-9805.noarch.rpm
3、将window下所有字体上传到服务器应用文件夹
windows字体目录:C:\WINDOWS\Fonts
应用字体目录:/opt/openoffice4/share/fonts/truetype/
4、启动openofiice4(指定服务器IP和端口,服务器外可以调用)
/opt/openoffice4/program/soffice -headless -accept="socket,host=192.0.0.22,port=8852;urp;" -nofirststartwizard &
5、相关问题解决
(1)缺少库文件
/opt/openoffice4/program/soffice.bin: error while loading shared libraries: libXext.so.6: cannot open shared object file: No such file or directory
yum install libXext.x86_64
cp -a /usr/lib64/libXext.so.6 /opt/openoffice4/program/
(2)未装插件
no suitable windowing system found, exiting.
yum groupinstall "X Window System"
项目集成
1、项目引入jodconverter-2.2.2.jar(解决word文档不支持docx、xlsx的问题)
解决方法一:下载jar包,用idea导入
解决方法二:下载jar包,上传到maven私服
mvn deploy:deploy-file -Dfile=jodconverter-2.2.2.jar -DgroupId=com.artofsolving -DartifactId=jodconverter -Dversion=2.2.2 -Dpackaging=jar -Durl=http://www.baidu.com:28081/repository/powersi-release/ -DrepositoryId=maven-repository-releases --settings D:/soft/apache-maven-3.5.4/conf/settings.xml
2、pom.xml引入依赖
<dependency>
<groupId>com.artofsolvinggroupId>
<artifactId>jodconverterartifactId>
<version>2.2.2version>
dependency>
<dependency>
<groupId>com.github.livesensegroupId>
<artifactId>jodconverter-coreartifactId>
<version>1.0.5version>
dependency>
3、application.yml加入配置信息
jodconverter:
ip: 192.0.0.22
port: 8852
4、提供转换工具(后缀为pdf文件不做转换)
@Service
@Slf4j
public class FileTransService {
@Value("${jodconverter.ip}")
private String ip;
@Value("${jodconverter.port}")
private int port;
private static final String PDF = "pdf";
public synchronized byte[] transFileToPdf(byte[] orignal, String suffix, String localPath) throws Exception {
byte[] rs = null;
// 原始文件数组为空或者后缀为pdf直接返回原数据
if (orignal == null || StringUtils.equals(suffix, PDF)) {
return orignal;
}
OpenOfficeConnection connection = new SocketOpenOfficeConnection(ip, port);
connection.connect();
DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);
String filename = UUID.randomUUID().toString();
// 首先将dtoBlob中的BLOB字段存到本地文件夹中
String sourcePath = localPath + File.separator + "emrDecode" + File.separator + filename + "." + suffix;
UtilFunc.writeFile(sourcePath, orignal);
String targetPath = localPath + File.separator + "emrDecode" + File.separator + filename + ".pdf";
File fileSource = new File(sourcePath);
File fileTarget = new File(targetPath);
try {
// 文件转化
converter.convert(fileSource, fileTarget);
if (fileTarget.exists()) {
rs = file2byte(fileTarget);
}
} catch (Exception e) {
log.warn(e.getMessage(), e);
} finally {
if (fileTarget.exists()) {
fileTarget.delete();
}
if (fileSource.exists()) {
fileSource.delete();
}
}
return rs;
}
private static byte[] file2byte(File tradeFile) {
byte[] buffer = null;
try {
FileInputStream fis = new FileInputStream(tradeFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int n;
while ((n = fis.read(b)) != -1) {
bos.write(b, 0, n);
}
fis.close();
bos.close();
buffer = bos.toByteArray();
} catch (IOException e) {
log.warn(e.getMessage(), e);
}
return buffer;
}
}
5、提供预览接口
@RestController
@RequestMapping("/web/sysFileAid")
public class SysFileAidController extends BaseController {
@Autowired
FileTransService fileTransService;
@GetMapping("/preview/{id}")
public void preview(@PathVariable("id") String id) throws Exception {
SysFileAidDTO sysFileAidDTO = sysFileAidService.querySysFileAidById(Long.valueOf(id));
DownloadByteArray callback = new DownloadByteArray();
byte[] bytes = fastFileStorageClient.downloadFile(sysFileAidDTO.getGroupName(), sysFileAidDTO.getFilePath(), callback);
byte[] pdfBytes = fileTransService.transFileToPdf(bytes, sysFileAidDTO.getFileType(), FileProperties.getProfile());
httpServletResponse.setContentType("application/pdf");
httpServletResponse.getOutputStream().write(pdfBytes);
httpServletResponse.getOutputStream().close();
}
}
评论
15种时间序列预测方法总结(包含多种方法代码实现)
向AI转型的程序员都关注了这个号👇👇👇在这篇文章中,我们将深入探讨时间序列预测的基本概念和方法。我们将首先介绍单元预测和多元预测的概念,然后详细介绍各种深度学习和传统机器学习方法如何应用于时间序列预测,包括循环神经网络(RNN)、一维卷积神经网络(1D-CNN)、Transformer、自回归模型(
机器学习AI算法工程
0
SpringBoot 实现图片防盗链功能
程序员的成长之路互联网/程序员/技术/资料共享 关注阅读本文大概需要 4 分钟。来自:blog.csdn.net/weixin_46157208/article/details/138051737前言出于安全考虑,我们需要后端返回的图片只允许在某个网站内展示,不想被爬虫拿到图片地
程序员的成长之路
0
有意思!一个关于 Spring 历史的在线小游戏
发现 Spring One 的官网上有个好玩的彩蛋,分享给大家!进到Spring One的官网,可以看到右下角有个类似马里奥游戏中的金币图标。点击该金币之后,会打开一个新的页面,进入下面这样一个名为:The History Of Spring 的在线小游戏你可以使用上下左右的方向键来控制Spring
公众号程序猿DD
1
一站式解决方案:基于 Arthas 实现服务发现和权限控制
来源:juejin.cn/post/7281849496983994383👉 欢迎加入小哈的星球 ,你将获得: 专属的项目实战 / Java 学习路线 / 一对一提问 / 学习打卡 / 赠书福利全栈前后端分离博客项目 2.0 版本完结啦, 演示链接
小哈学Java
0
用 Shader 实现旗帜飘扬动画效果
我觉得对于刚入门 3D 编程的朋友来说,如果能够完成代码创建模型数据->创建材质->编写Shader动画这一系列,想必会有满满的成就感。今天就用 Cocos Creator 的 utils.MeshUtils.createMesh 接口,带大家感受一下这个流程。这个流程不仅可以用于新手学
COCOS
2
Stability AI开放Stable Diffusion 3 API,在线免费使用
「Stability AI」宣布开放其最新文本到图像生成模型「Stable Diffusion 3」的API接口,供开发者和企业使用。该模型采用创新的多模态扩散转换器架构,在字体、细节还原、提示理解等方面表现优异,评测结果超越了业内其他顶尖系统。与DALL-E 3和Midjourney v6等最先进
IQ前端
0
SpringBoot+Minio实现上传凭证、分片上传、秒传和断点续传
关注我们,设为星标,每天7:40不见不散,架构路上与您共享回复架构师获取资源大家好,我是你们的朋友架构君,一个会写代码吟诗的架构师。Spring Boot整合Minio后,前端的文件上传有两种方式:1、文件上传到后端,由后端保存到Minio这种方式好处是完全由后端集中管理,可以很好的做到、身份验证、
Java架构师社区
0
浅谈几款XML文档解析工具以及优缺点
一、简介XML,一种可扩展标记语言,通常被开发人员用来传输和存储数据,定义也比较简单,通常如下方式开头,用来表述文档的一些信息。<?xml version="1.0" encoding="UTF-8"?>例如下面这个简单的文档。<?xml versio
Stephen
1