From c28e9990179f5573ea94f41130fcec8c64f7902a Mon Sep 17 00:00:00 2001 From: shichongfu <shi_chongfu@163.com> Date: 星期三, 07 六月 2023 17:09:14 +0800 Subject: [PATCH] 文档转换新转换方式,在properties中配置,open office是否启用 --- src/main/java/com/product/file/util/FileUtils.java | 21 ++++++++++++++++----- 1 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/product/file/util/FileUtils.java b/src/main/java/com/product/file/util/FileUtils.java index 789d00f..77416f6 100644 --- a/src/main/java/com/product/file/util/FileUtils.java +++ b/src/main/java/com/product/file/util/FileUtils.java @@ -557,9 +557,10 @@ if (placeLocation.indexOf("/") != 0) { placeLocation += "/"; } + //绾跨▼鍚屾 if (threadSync) { - boolean b = convertPdf(uploadServer, isEncrypt, file, placeLocation, fileName); + boolean b = convertPdf(uploadServer, isEncrypt, file, placeLocation, fileName +"."+tail); if (deleteFile && file.isFile()) { file.delete(); } @@ -569,7 +570,7 @@ String finalPlaceLocation = placeLocation; final File ff = FileUtil.copyFile(file, Global.getSystemConfig("temp.dir", "") + "/" + "temp_convert_pdf_" + RandomUtil.randomString(5) + "_" + file.getName(), 0); executorService.submit(() -> { - convertPdf(uploadServer, isEncrypt, ff, finalPlaceLocation, fileName); + convertPdf(uploadServer, isEncrypt, ff, finalPlaceLocation, fileName+"."+tail); if (ff.isFile()) { ff.delete(); } @@ -588,20 +589,30 @@ String tempPath = Global.getSystemConfig("temp.dir", "./attachment/temp") + "/" + "convertPDF_" + random + "_" + file.getName(); String tempPathSuccess = Global.getSystemConfig("temp.dir", "./attachment/temp") + "/" + "convertPDF_success_" + random + ".pdf"; try { + int lastIndex = fileName.lastIndexOf("."); + String officeType = fileName.substring(lastIndex+1); + fileName=fileName.substring(0,lastIndex); FileUtil.copyFile(file, tempPath, 0); - pdfFile = PdfConcurrenceUtil.convertToPdf(tempPath, tempPathSuccess); + if(Global.getPropertyToBoolean("open.office.isEnable", "true")) {//鍚敤oepn office杞崲 + pdfFile = PdfConcurrenceUtil.convertToPdf(tempPath, tempPathSuccess); + }else{ + pdfFile = new File(AsposeUtil.OfficeToPdf(tempPath, tempPathSuccess,officeType)); + } String s = Global.getSystemConfig("temp.dir", "") + "/" + "convertPDF_encryptTemp_" + random + ".pdf"; FileUtil.copyFile(pdfFile, s, isEncrypt ? 1 : 0); pdfFile.delete(); pdfFile = new File(s); uploadOtherFile(false, uploadServer, placeLocation, pdfFile, fileName); return true; - } catch (Exception e) { + } + catch (BaseException e) { + throw e; + }catch (Exception e) { e.printStackTrace(); throw new BaseException(FileCode.CONVERT_PDF_FILE_FAIL); } finally { try { - if (pdfFile.isFile()) { + if (pdfFile !=null && pdfFile.isFile()) { pdfFile.delete(); } com.product.common.io.FileUtils.delFile(tempPath); -- Gitblit v1.9.2