分享一個(gè)超牛逼的 Java 文件在線預(yù)覽項(xiàng)目
簡(jiǎn)介
內(nèi)置功能
文件上傳功能
文件轉(zhuǎn)換功能
文件預(yù)覽功能
遠(yuǎn)程文件預(yù)覽功能
代碼集成
# 默認(rèn)不開啟 需要開啟的設(shè)置成true
jodconverter.local.enabled=true
# 開啟多個(gè)openOffice進(jìn)程,每個(gè)端口對(duì)應(yīng)一個(gè)進(jìn)程
jodconverter.local.portNumbers=8100,8200
# openOffice進(jìn)程重啟前的最大進(jìn)程數(shù)
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;
/**
* 實(shí)時(shí)轉(zhuǎn)換
*/
logger.info("開始轉(zhuǎn)換pdf......");
File toFile = new File(parentFile, uuid + ".pdf");
documentConverter.convert(docFile).to(toFile).execute();
logger.info("開始轉(zhuǎn)換html......");
toFile = new File(parentFile, uuid + ".html");
converter( docFile,toFile);
return Result.ok(imagePath);
} else {
return Result.error();
}
} catch (Exception e) {
logger.error("轉(zhuǎn)換異常{}",e);
return Result.error();
}
}
}
軟件截圖







小結(jié)
源碼
END
順便給大家推薦一個(gè)GitHub項(xiàng)目,這個(gè) GitHub 整理了上千本常用技術(shù)PDF,絕大部分核心的技術(shù)書籍都可以在這里找到,
GitHub地址:https://github.com/javadevbooks/books
Gitee地址:https://gitee.com/javadevbooks/books
電子書已經(jīng)更新好了,你們需要的可以自行下載了,記得點(diǎn)一個(gè)star,持續(xù)更新中..
評(píng)論
圖片
表情

