diff --git a/src/main/java/com/docus/sw/fenpan/MyApplication.java b/src/main/java/com/docus/sw/fenpan/MyApplication.java index 731ce05..0659b5e 100644 --- a/src/main/java/com/docus/sw/fenpan/MyApplication.java +++ b/src/main/java/com/docus/sw/fenpan/MyApplication.java @@ -354,7 +354,11 @@ public class MyApplication { // 执行长时间运行的业务操作 // 模拟耗时操作 - new SuoyinService().index(filePathField.getText()); + try { + new SuoyinService().index(filePathField.getText()); + } catch (IOException ex) { + throw new RuntimeException(ex); + } SwingUtilities.invokeLater(new Runnable() { @Override diff --git a/src/main/java/com/docus/sw/souyin/PdfUtil.java b/src/main/java/com/docus/sw/souyin/PdfUtil.java index aee30f9..aa44200 100644 --- a/src/main/java/com/docus/sw/souyin/PdfUtil.java +++ b/src/main/java/com/docus/sw/souyin/PdfUtil.java @@ -72,7 +72,7 @@ public class PdfUtil { List fileList = new ArrayList<>(); for (int i = 0; i < pageCount; i++) { //只有一页的时候文件名为传入的文件名,大于一页的文件名为:文件名_自增加数字(从1开始) - String realFileName = pageCount > 1 ? desFileName + "" + (i + 1) : desFileName; + String realFileName = pageCount > 1 ? desFileName + "" + String.format("%03d",(i + 1)) : desFileName; //每一页通过分辨率和颜色值进行转化 BufferedImage bufferedImage = renderer.renderImageWithDPI(i, 150 * 2, ImageType.RGB); String filePath = desFilePath + File.separator + realFileName + "." + imageType; @@ -122,7 +122,7 @@ public class PdfUtil { int j = 1; for (int i = pageCount-1; i >= 0; i--) { //只有一页的时候文件名为传入的文件名,大于一页的文件名为:文件名_自增加数字(从1开始) - String realFileName = pageCount > 1 ? desFileName + "" + j : desFileName; + String realFileName = pageCount > 1 ? desFileName + "" + String.format("%03d",(j)) : desFileName; //每一页通过分辨率和颜色值进行转化 BufferedImage bufferedImage = renderer.renderImageWithDPI(i, 150 * 2, ImageType.RGB); String filePath = desFilePath + File.separator + realFileName + "." + imageType; diff --git a/src/main/java/com/docus/sw/souyin/SuoyinService.java b/src/main/java/com/docus/sw/souyin/SuoyinService.java index e959f1c..539b418 100644 --- a/src/main/java/com/docus/sw/souyin/SuoyinService.java +++ b/src/main/java/com/docus/sw/souyin/SuoyinService.java @@ -1,11 +1,13 @@ package com.docus.sw.souyin; import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.util.FileUtils; import com.docus.sw.Config; import com.docus.sw.fenpan.Document; import com.docus.sw.fenpan.FileTypeEnum; import com.docus.sw.fenpan.Pieces; import com.docus.sw.fenpan.Roll; +import com.drew.tools.FileUtil; import com.google.gson.Gson; import org.apache.commons.imaging.ImageInfo; import org.apache.commons.imaging.ImageReadException; @@ -15,6 +17,9 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.nio.file.CopyOption; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -35,7 +40,7 @@ public class SuoyinService { new SuoyinService().index(path); } - public void index(String path) { + public void index(String path) throws IOException { Map map = new HashMap<>(); findAllDir(path, map); @@ -195,12 +200,22 @@ public class SuoyinService { ExcelUtil.toPdf(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".xls",indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf"); //写入文件夹。 - PdfToPic.toPic(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf",indexPlate.getAbsolutePath()+"/片头","0000","jpg"); + PdfToPic.toPic(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf",indexPlate.getAbsolutePath()+"/片头","01","jpg"); - PdfToPic.toPicDesc(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf",indexPlate.getAbsolutePath()+"/片尾","0010","jpg"); + PdfToPic.toPicDesc(indexPlate.getAbsolutePath()+"/"+indexPlate.getName()+".pdf",indexPlate.getAbsolutePath()+"/片尾","00","jpg"); + File pdf = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); //再重算一次索引,以及将文件进行替换。 + File parentFile = pdf.getParentFile().getParentFile(); + File file = new File(parentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".pdf"); + Files.move(pdf.toPath(),file.toPath(), StandardCopyOption.ATOMIC_MOVE); + + File xls = new File(indexPlate.getAbsolutePath() + "/" + indexPlate.getName() + ".xls"); + //再重算一次索引,以及将文件进行替换。 + File xlsParentFile = xls.getParentFile().getParentFile(); + File file2 = new File(xlsParentFile.getAbsolutePath() + "/" + indexPlate.getName() + ".xls"); + Files.move(xls.toPath(),file2.toPath()); }