一个超牛逼的 Java 文件在线预览项目
程序员闪充宝
共 2697字,需浏览 6分钟
·
2021-07-27 12:47
简介
内置功能
文件上传功能
文件转换功能
文件预览功能
远程文件预览功能
代码集成
# 默认不开启 需要开启的设置成true
jodconverter.local.enabled=true
# 开启多个openOffice进程,每个端口对应一个进程
jodconverter.local.portNumbers=8100,8200
# openOffice进程重启前的最大进程数
jodconverter.local.maxTasksPerProcess=100
@RestController
@RequestMapping("document")
public class ConverterController {
@Autowired
private DocumentConverter documentConverter;
/**
* 文件上传
*/
@RequestMapping("/upload")
public Result upload(MultipartFile file) {
try {
if (file != null) {
File parentFile = createParentFile();
String fileName = file.getOriginalFilename();
String suffix = fileName.substring(fileName.lastIndexOf("."));
String uuid = IdUtil.simpleUUID();
fileName = uuid + suffix;
File docFile = new File(parentFile, fileName);
FileUtil.writeFromStream(file.getInputStream(), docFile);
/**
* 年月日目录
*/
String fileDay = DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/"
+ DateUtil.thisDayOfMonth();
String imagePath = SystemConstant.FILE + "/document/" + fileDay + "/" + fileName;
/**
* 实时转换
*/
logger.info("开始转换pdf......");
File toFile = new File(parentFile, uuid + ".pdf");
documentConverter.convert(docFile).to(toFile).execute();
logger.info("开始转换html......");
toFile = new File(parentFile, uuid + ".html");
converter( docFile,toFile);
return Result.ok(imagePath);
} else {
return Result.error();
}
} catch (Exception e) {
logger.error("转换异常{}",e);
return Result.error();
}
}
}
软件截图
![null](https://filescdn.proginn.com/aa578aa9b72e422969ef0e9dfbf1993c/9f6a0fd6d663af061a02ff76b08c0ab3.webp)
![null](https://filescdn.proginn.com/9afd0a7c3edce814a4bbc3106c274413/fa2ecd27152f1244b33d269e8e025600.webp)
![null](https://filescdn.proginn.com/80d15e69aaf118d7f859df4d4e9dab92/2cf0c9217e53bcd869b36f94e6cfa641.webp)
![](https://filescdn.proginn.com/e6afc70346c798c7b39f24fd0106e6d2/d3fedcea1f573fc675f4124fad0b017f.webp)
![null](https://filescdn.proginn.com/974a23a68dbfdf28af5a1f6bf694bd91/7ea35a68346133785f83d90a7fea8040.webp)
![null](https://filescdn.proginn.com/980d0eadd713be457a197ec7d7f18fe0/112062a964e5093fdd84667bf3b496d5.webp)
![null](https://filescdn.proginn.com/3e434f98906c4e7719bc753d609351ad/1274bfe0b42587dc564e02dcc0256892.webp)
小结
源码
评论