<dependency>
<groupId>com.luhuiguo</groupId>
<artifactId>aspose-words</artifactId>
<version>23.1</version>
</dependency>
@Override
public String wordToFile(MultipartFile file, String type) {
String checkType = FilenameUtils.getExtension(file.getOriginalFilename());
if (!"doc".equals(checkType) && !"docx".equals(checkType)) {
throw new ServiceException(1, "输入文件不是Word文件!");
}
try {
switch (type.toUpperCase()) {
case "TEXT" : {
return switchFile(file, SaveFormat.TEXT, "txt");
}
case "PDF" : {
return switchFile(file, com.aspose.words.SaveFormat.PDF, "pdf");
}
/*************** 需要操作每一页Word文件,一般Word类的直接电脑操作,应该用不上************/
// case "PNG" : {
// return switchFile(file, com.aspose.words.SaveFormat.PNG, "png");
// }
// case "JPG" : {
// return switchFile(file, com.aspose.words.SaveFormat.JPEG, "jpg");
// }
default:{}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private String switchFile(MultipartFile file, int saveFormat, String suffix){
String url = "";
try {
long old = System.currentTimeMillis();
// 输出路径
String fileName = UUID.randomUUID() + "." + suffix;
String filePath = ossUpLoadTools.getSavePath() + "/" + fileName;
FileOutputStream os = new FileOutputStream(filePath);
com.aspose.words.Document doc = new com.aspose.words.Document(file.getInputStream());
doc.save(os, saveFormat);
os.close();
File outputfile = new File(filePath);
url = ossUpLoadTools.uploadOssFile(fileName, outputfile);
outputfile.delete();
long now = System.currentTimeMillis();
log.info("共耗时:" + ((now - old) / 1000.0) + "秒");
}catch (Exception e) {
e.printStackTrace();
}
return url;
}
<dependency>
<groupId>com.luhuiguo</groupId>
<artifactId>aspose-slides</artifactId>
<version>23.1</version>
</dependency>
@Override
public String PptToFile(MultipartFile file, String type) {
// 获取文件后缀名
String checkType = FilenameUtils.getExtension(file.getOriginalFilename());
if (!"ppt".equals(checkType) && !"pptx".equals(checkType)) {
throw new ServiceException(1, "输入文件不是PPT文件!");
}
try {
switch (type.toUpperCase()) {
case "HTML" : {
return SwitchFile(file, com.aspose.slides.SaveFormat.Html, "html");
}
case "HTML5" : {
return SwitchFile(file, com.aspose.slides.SaveFormat.Html5, "html");
}
case "PDF" : {
return SwitchFile(file, com.aspose.slides.SaveFormat.Pdf, "pdf");
}
default:{}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private String SwitchFile(MultipartFile file, int saveFormat, String suffix) {
String url = "";
try {
long old = System.currentTimeMillis();
String fileName = UUID.ra