|
|
|
@ -7,6 +7,9 @@ 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.docus.sw.word.GetPicsDocx;
|
|
|
|
|
import com.docus.sw.word.PdfBoxUtils;
|
|
|
|
|
import com.docus.sw.word.ReadImgDoc;
|
|
|
|
|
import com.drew.tools.FileUtil;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import org.apache.commons.imaging.ImageInfo;
|
|
|
|
@ -72,50 +75,69 @@ public class SuoyinService {
|
|
|
|
|
for(File piece:piecesFile){
|
|
|
|
|
|
|
|
|
|
//区分word和pdf
|
|
|
|
|
if(piece.getName().endsWith(".doc")){
|
|
|
|
|
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
|
|
|
|
|
|
|
|
|
|
List<Document> documentList = new ArrayList<>();
|
|
|
|
|
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName());
|
|
|
|
|
for (File docfile : piece.listFiles()) {
|
|
|
|
|
File temp = new File("temp");
|
|
|
|
|
if(!temp.exists()){
|
|
|
|
|
temp.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ReadImgDoc.readPicture(piece.getAbsolutePath(),temp.getAbsolutePath());
|
|
|
|
|
try {
|
|
|
|
|
PdfBoxUtils.pdf2image(piece.getAbsolutePath(),temp.getAbsolutePath());
|
|
|
|
|
File[] listFiles = temp.listFiles();
|
|
|
|
|
genPieces(pieces, listFiles);
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//删除对应的temp 文件
|
|
|
|
|
file.delete();
|
|
|
|
|
}else if(piece.getName().endsWith(".docx")){
|
|
|
|
|
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
|
|
|
|
|
|
|
|
|
|
File temp = new File("temp");
|
|
|
|
|
if(!temp.exists()){
|
|
|
|
|
temp.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetPicsDocx.getPics(piece.getAbsolutePath(),temp.getAbsolutePath());
|
|
|
|
|
try {
|
|
|
|
|
PdfBoxUtils.pdf2image(piece.getAbsolutePath(),temp.getAbsolutePath());
|
|
|
|
|
File[] listFiles = temp.listFiles();
|
|
|
|
|
genPieces(pieces, listFiles);
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
|
|
//非图片模式,跳过。
|
|
|
|
|
if(!(docfile.getName().endsWith(".jpg") || docfile.getName().endsWith(".png")
|
|
|
|
|
|| docfile.getName().endsWith(".jpeg") || docfile.getName().endsWith(".tif")
|
|
|
|
|
|| docfile.getName().endsWith(".tiff")|| file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm"))|| file.getName().endsWith(".gif")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (file.getName().endsWith(".jp2") || file.getName().endsWith(".jpm")) {
|
|
|
|
|
// 读取 JPEG 2000 图像文件
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
BufferedImage image = ImageIO.read(file);
|
|
|
|
|
int height = image.getHeight();
|
|
|
|
|
int width = image.getWidth();
|
|
|
|
|
Document document = new Document(width, height, 300);
|
|
|
|
|
documentList.add(document);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
ImageInfo imageInfo = Imaging.getImageInfo(docfile);
|
|
|
|
|
int height = imageInfo.getHeight();
|
|
|
|
|
int width = imageInfo.getWidth();
|
|
|
|
|
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
|
|
|
|
|
Document document = new Document(width, height, physicalHeightDpi);
|
|
|
|
|
documentList.add(document);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("非图片格式", e);
|
|
|
|
|
} catch (ImageReadException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
//删除对应的temp 文件
|
|
|
|
|
file.delete();
|
|
|
|
|
}else if(piece.getName().endsWith(".pdf")){
|
|
|
|
|
Pieces pieces = new Pieces(FileTypeEnum.DOC, piece.getAbsolutePath(), piece.getName());
|
|
|
|
|
|
|
|
|
|
File temp = new File("temp");
|
|
|
|
|
if(!temp.exists()){
|
|
|
|
|
temp.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetPicsDocx.getPics(piece.getAbsolutePath(),temp.getAbsolutePath());
|
|
|
|
|
try {
|
|
|
|
|
PdfBoxUtils.pdf2image(piece.getAbsolutePath(),temp.getAbsolutePath());
|
|
|
|
|
File[] listFiles = temp.listFiles();
|
|
|
|
|
genPieces(pieces, listFiles);
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//删除对应的temp 文件
|
|
|
|
|
file.delete();
|
|
|
|
|
}else{
|
|
|
|
|
Pieces pieces = new Pieces(FileTypeEnum.JPG, piece.getAbsolutePath(), piece.getName());
|
|
|
|
|
File[] listFiles = piece.listFiles();
|
|
|
|
|
genPieces(pieces, listFiles);
|
|
|
|
|
pieceList.add(pieces);
|
|
|
|
|
}
|
|
|
|
|
pieces.put(documentList);
|
|
|
|
|
pieceList.add(pieces);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -230,6 +252,48 @@ public class SuoyinService {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void genPieces(Pieces pieces, File[] listFiles) {
|
|
|
|
|
List<Document> documentList = new ArrayList<>();
|
|
|
|
|
for (File docfile : listFiles) {
|
|
|
|
|
//非图片模式,跳过。
|
|
|
|
|
if(!(docfile.getName().endsWith(".jpg") || docfile.getName().endsWith(".png")
|
|
|
|
|
|| docfile.getName().endsWith(".jpeg") || docfile.getName().endsWith(".tif")
|
|
|
|
|
|| docfile.getName().endsWith(".tiff")|| docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm"))|| docfile.getName().endsWith(".gif")){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (docfile.getName().endsWith(".jp2") || docfile.getName().endsWith(".jpm")) {
|
|
|
|
|
// 读取 JPEG 2000 图像文件
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
BufferedImage image = ImageIO.read(docfile);
|
|
|
|
|
int height = image.getHeight();
|
|
|
|
|
int width = image.getWidth();
|
|
|
|
|
Document document = new Document(width, height, 300);
|
|
|
|
|
documentList.add(document);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
ImageInfo imageInfo = Imaging.getImageInfo(docfile);
|
|
|
|
|
int height = imageInfo.getHeight();
|
|
|
|
|
int width = imageInfo.getWidth();
|
|
|
|
|
int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
|
|
|
|
|
Document document = new Document(width, height, physicalHeightDpi);
|
|
|
|
|
documentList.add(document);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException("非图片格式", e);
|
|
|
|
|
} catch (ImageReadException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pieces.put(documentList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<IndexPageRow> indexGen(IndexPlate indexPlate, List<Roll> rollList, Integer pianPageNum, Integer totalSize) {
|
|
|
|
|
List<IndexPageRow> indexPageRows = new ArrayList<>();
|
|
|
|
|
int start = 1;
|
|
|
|
|