解决pdf 的加载问题

master
zhanghai 2 years ago
parent 23395da24d
commit 7cd20468ec

@ -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

@ -72,7 +72,7 @@ public class PdfUtil {
List<Object> 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;

@ -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<String,IndexPlate> 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());
}

Loading…
Cancel
Save