|
@@ -1,5 +1,6 @@
|
|
package com.qmth.distributed.print.business.util;
|
|
package com.qmth.distributed.print.business.util;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.itextpdf.text.Document;
|
|
import com.itextpdf.text.Document;
|
|
import com.itextpdf.text.Rectangle;
|
|
import com.itextpdf.text.Rectangle;
|
|
import com.itextpdf.text.pdf.*;
|
|
import com.itextpdf.text.pdf.*;
|
|
@@ -165,21 +166,15 @@ public class PdfUtil {
|
|
PageSizeEnum pageSizeEnum = null;
|
|
PageSizeEnum pageSizeEnum = null;
|
|
for (int i = 1; i <= totalPages; i++) {
|
|
for (int i = 1; i <= totalPages; i++) {
|
|
Rectangle pageSize = reader.getPageSize(i);
|
|
Rectangle pageSize = reader.getPageSize(i);
|
|
|
|
+ System.out.println(JSON.toJSONString(pageSize));
|
|
float width = pageSize.getWidth();
|
|
float width = pageSize.getWidth();
|
|
float height = pageSize.getHeight();
|
|
float height = pageSize.getHeight();
|
|
- if (width <= height) {
|
|
|
|
- min = width;
|
|
|
|
- max = height;
|
|
|
|
- } else {
|
|
|
|
- min = height;
|
|
|
|
- max = width;
|
|
|
|
- }
|
|
|
|
if (pageSizeEnum != null) {
|
|
if (pageSizeEnum != null) {
|
|
- if (!pageSizeEnum.equals(PageSizeEnum.convertToEnum(min, max))) {
|
|
|
|
|
|
+ if (!pageSizeEnum.equals(PageSizeEnum.convertToEnum(width, height))) {
|
|
throw ExceptionResultEnum.ERROR.exception("上传的试卷pdf中存在纸张格式不一样的");
|
|
throw ExceptionResultEnum.ERROR.exception("上传的试卷pdf中存在纸张格式不一样的");
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- pageSizeEnum = PageSizeEnum.convertToEnum(min, max);
|
|
|
|
|
|
+ pageSizeEnum = PageSizeEnum.convertToEnum(width, height);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -272,4 +267,21 @@ public class PdfUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ File file2 = new File("E:\\file\\1.pdf");
|
|
|
|
+ try {
|
|
|
|
+ System.out.println(PdfUtil.getPdfFormat(file2));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ File file1 = new File("E:\\file\\1左.pdf");
|
|
|
|
+ try {
|
|
|
|
+ System.out.println(PdfUtil.getPdfFormat(file1));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|