mirror of https://gitee.com/xiaonuobase/snowy
【更新】优化代码,pdf文件预览无需转换
parent
ce70caa824
commit
7e2eeaef7c
|
@ -96,4 +96,29 @@ public interface MediaTypeConstant {
|
|||
* 文档pptx格式
|
||||
*/
|
||||
String DOC_PPTX = "pptx";
|
||||
|
||||
/**
|
||||
* 文档pdf格式
|
||||
*/
|
||||
String DOC_PDF = "pdf";
|
||||
|
||||
/**
|
||||
* 文件html格式
|
||||
*/
|
||||
String FILE_HTML = "html";
|
||||
|
||||
/**
|
||||
* 文件htm格式
|
||||
*/
|
||||
String FILE_HTM = "htm";
|
||||
|
||||
/**
|
||||
* 文件swf格式
|
||||
*/
|
||||
String FILE_SWF = "swf";
|
||||
|
||||
/**
|
||||
* 文件flash格式
|
||||
*/
|
||||
String FILE_FLASH = "flash";
|
||||
}
|
||||
|
|
|
@ -45,19 +45,21 @@ public class LibreOfficeUtil {
|
|||
* @date 2020/7/6 15:02
|
||||
*/
|
||||
public static void convertToPdf(InputStream inputStream, OutputStream outputStream, String fileSuffix) {
|
||||
init();
|
||||
final DocumentFormatEnum documentFormatEnum = DocumentFormatEnum.valueOf(fileSuffix.toUpperCase());
|
||||
final DocumentFormat format = documentFormatEnum.getFormFormat();
|
||||
log.info(">>> 待转换的文档类型:{}", format);
|
||||
final DocumentFormat targetFormat = documentFormatEnum.getTargetFormat();
|
||||
log.info(">>> 转换的目标文档类型:{}", targetFormat);
|
||||
try {
|
||||
final InputStream is = documentFormatEnum.getInputStream(inputStream);
|
||||
documentConverter.convert(is).as(format).to(outputStream).as(targetFormat).execute();
|
||||
} catch (IOException | OfficeException e) {
|
||||
e.printStackTrace();
|
||||
if(!MediaTypeConstant.DOC_PDF.equals(fileSuffix)) {
|
||||
init();
|
||||
final DocumentFormatEnum documentFormatEnum = DocumentFormatEnum.valueOf(fileSuffix.toUpperCase());
|
||||
final DocumentFormat format = documentFormatEnum.getFormFormat();
|
||||
log.info(">>> 待转换的文档类型:{}", format);
|
||||
final DocumentFormat targetFormat = documentFormatEnum.getTargetFormat();
|
||||
log.info(">>> 转换的目标文档类型:{}", targetFormat);
|
||||
try {
|
||||
final InputStream is = documentFormatEnum.getInputStream(inputStream);
|
||||
documentConverter.convert(is).as(format).to(outputStream).as(targetFormat).execute();
|
||||
} catch (IOException | OfficeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info(">>> 文件转换结束");
|
||||
}
|
||||
log.info(">>> 文件转换结束");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,7 +90,8 @@ public class LibreOfficeUtil {
|
|||
|| MediaTypeConstant.DOC_XLS.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_XLSX.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_PPT.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_PPTX.equals(fileSuffix);
|
||||
|| MediaTypeConstant.DOC_PPTX.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_PDF.equals(fileSuffix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,7 +106,8 @@ public class LibreOfficeUtil {
|
|||
|| MediaTypeConstant.DOC_DOC.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_DOCX.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_PPT.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_PPTX.equals(fileSuffix)) {
|
||||
|| MediaTypeConstant.DOC_PPTX.equals(fileSuffix)
|
||||
|| MediaTypeConstant.DOC_PDF.equals(fileSuffix)) {
|
||||
return MediaType.APPLICATION_PDF_VALUE;
|
||||
} else {
|
||||
//否则是html类型
|
||||
|
|
Loading…
Reference in New Issue