| | |
| | | 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(); |
| | |
| | | * @param output |
| | | * @return |
| | | */ |
| | | @Deprecated |
| | | public static File convertToPdf(String input, String output) throws Exception { |
| | | File inputFile = null; |
| | | File outFile = null; |
| | |
| | | } |
| | | return outFile; |
| | | } |
| | | /** |
| | | * 转换pdf |
| | | * @param input |
| | | * @param output |
| | | * @return |
| | | */ |
| | | public static File convertToPdf(String input, String output,String officeType) throws Exception { |
| | | File inputFile = null; |
| | | File outFile = null; |
| | | OfficeManager officeManager = null; |
| | | try { |
| | | if(Global.getPropertyToBoolean("open.office.isEnable", "true")) {//启用oepn office转换 |
| | | officeManager = officeManagerQueue.take(); |
| | | inputFile = new File(input); |
| | | outFile = new File(output); |
| | | SpringMVCContextHolder.getSystemLogger().info("开始转换文档:" + input + "=>" + output); |
| | | OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); |
| | | converter.convert(inputFile, outFile); // 转换文档 |
| | | }else{ |
| | | outFile = new File(AsposeUtil.OfficeToPdf(input, output,officeType)); |
| | | } |
| | | |
| | | }catch (Exception e) { |
| | | outFile = null; |
| | | throw e; |
| | | } finally { |
| | | SpringMVCContextHolder.getSystemLogger().info("结束转换文档"); |
| | | if (officeManager != null) { |
| | | try { |
| | | officeManagerQueue.put(officeManager); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return outFile; |
| | | } |
| | | } |