|
@@ -157,18 +157,29 @@ public class PdfUtil {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
*/
|
|
*/
|
|
public static PageSizeEnum getPdfFormat(File file) throws IOException {
|
|
public static PageSizeEnum getPdfFormat(File file) throws IOException {
|
|
|
|
+ float min;
|
|
|
|
+ float max;
|
|
Optional.ofNullable(file).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("文件不能为空"));
|
|
Optional.ofNullable(file).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("文件不能为空"));
|
|
PdfReader reader = new PdfReader(ByteArray.fromFile(file).value());
|
|
PdfReader reader = new PdfReader(ByteArray.fromFile(file).value());
|
|
int totalPages = reader.getNumberOfPages();
|
|
int totalPages = reader.getNumberOfPages();
|
|
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);
|
|
|
|
+ float width = pageSize.getWidth();
|
|
|
|
+ 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(pageSize.getWidth(), pageSize.getHeight()))){
|
|
|
|
|
|
+ if (!pageSizeEnum.equals(PageSizeEnum.convertToEnum(min, max))){
|
|
throw ExceptionResultEnum.ERROR.exception("上传的试卷pdf中存在纸张格式不一样的");
|
|
throw ExceptionResultEnum.ERROR.exception("上传的试卷pdf中存在纸张格式不一样的");
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
- pageSizeEnum = PageSizeEnum.convertToEnum(pageSize.getWidth(), pageSize.getHeight());
|
|
|
|
|
|
+ pageSizeEnum = PageSizeEnum.convertToEnum(min, max);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|