|
@@ -46,27 +46,29 @@ public class PdfUtil {
|
|
PdfReader reader = null;
|
|
PdfReader reader = null;
|
|
StringJoiner dirName = null;
|
|
StringJoiner dirName = null;
|
|
try {
|
|
try {
|
|
- document = new Document(new PdfReader(files[0]).getPageSize(1));
|
|
|
|
- if (Objects.isNull(outputPath)) {
|
|
|
|
- LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
- StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
|
|
|
|
- dirName = new StringJoiner("")
|
|
|
|
- .add(UploadFileEnum.PDF.getTitle()).add(File.separator)
|
|
|
|
- .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
- .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
- .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.PDF_PREFIX);
|
|
|
|
- outputPath = stringJoiner.toString() + dirName.toString();
|
|
|
|
- }
|
|
|
|
- copy = new PdfSmartCopy(document, new FileOutputStream(outputPath));
|
|
|
|
- document.open();
|
|
|
|
- for (int i = 0; i < files.length; i++) {
|
|
|
|
- reader = new PdfReader(files[i]);
|
|
|
|
- int numberOfPages = reader.getNumberOfPages();
|
|
|
|
- for (int j = 1; j <= numberOfPages; j++) {
|
|
|
|
- document.newPage();
|
|
|
|
- PdfImportedPage page = copy.getImportedPage(reader, j);
|
|
|
|
- copy.addPage(page);
|
|
|
|
|
|
+ if (Objects.nonNull(files) && files.length > 0) {
|
|
|
|
+ document = new Document(new PdfReader(files[0]).getPageSize(1));
|
|
|
|
+ if (Objects.isNull(outputPath)) {
|
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
|
|
|
|
+ dirName = new StringJoiner("")
|
|
|
|
+ .add(UploadFileEnum.PDF.getTitle()).add(File.separator)
|
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
|
+ .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.PDF_PREFIX);
|
|
|
|
+ outputPath = stringJoiner.toString() + dirName.toString();
|
|
|
|
+ }
|
|
|
|
+ copy = new PdfSmartCopy(document, new FileOutputStream(outputPath));
|
|
|
|
+ document.open();
|
|
|
|
+ for (int i = 0; i < files.length; i++) {
|
|
|
|
+ reader = new PdfReader(files[i]);
|
|
|
|
+ int numberOfPages = reader.getNumberOfPages();
|
|
|
|
+ for (int j = 1; j <= numberOfPages; j++) {
|
|
|
|
+ document.newPage();
|
|
|
|
+ PdfImportedPage page = copy.getImportedPage(reader, j);
|
|
|
|
+ copy.addPage(page);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|