| | |
| | | if (placeLocation.indexOf("/") != 0) { |
| | | placeLocation += "/"; |
| | | } |
| | | |
| | | //线程同步 |
| | | if (threadSync) { |
| | | boolean b = convertPdf(uploadServer, isEncrypt, file, placeLocation, fileName +"."+tail); |
| | | boolean b = convertPdf(uploadServer, isEncrypt, file, placeLocation, fileName,tail); |
| | | if (deleteFile && file.isFile()) { |
| | | file.delete(); |
| | | } |
| | |
| | | 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+"."+tail); |
| | | convertPdf(uploadServer, isEncrypt, ff, finalPlaceLocation, fileName,tail); |
| | | if (ff.isFile()) { |
| | | ff.delete(); |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | private static boolean convertPdf(boolean uploadServer, boolean isEncrypt, File file, String placeLocation, String fileName) throws BaseException { |
| | | private static boolean convertPdf(boolean uploadServer, boolean isEncrypt, File file, String placeLocation, String fileName,String officeType) throws BaseException { |
| | | File pdfFile = null; |
| | | String random = RandomUtil.randomString(5); |
| | | 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); |
| | | if(Global.getPropertyToBoolean("open.office.isEnable", "true")) {//启用oepn office转换 |
| | | pdfFile = PdfConcurrenceUtil.convertToPdf(tempPath, tempPathSuccess); |
| | | }else{ |
| | | pdfFile = new File(AsposeUtil.OfficeToPdf(tempPath, tempPathSuccess,officeType)); |
| | | } |
| | | pdfFile = PdfConcurrenceUtil.convertToPdf(tempPath, tempPathSuccess,officeType); |
| | | String s = Global.getSystemConfig("temp.dir", "") + "/" + "convertPDF_encryptTemp_" + random + ".pdf"; |
| | | FileUtil.copyFile(pdfFile, s, isEncrypt ? 1 : 0); |
| | | pdfFile.delete(); |
| | |
| | | throw new BaseException(FileCode.CONVERT_PDF_FILE_FAIL); |
| | | } finally { |
| | | try { |
| | | if (pdfFile !=null && pdfFile.isFile()) { |
| | | if (pdfFile!=null && pdfFile.isFile()) { |
| | | pdfFile.delete(); |
| | | } |
| | | com.product.common.io.FileUtils.delFile(tempPath); |