فهرست منبع

计量文件推送pdf大小默认设置A4大小

liuyc 1 سال پیش
والد
کامیت
51bb2866c6

+ 6 - 0
blade-service/blade-archive/pom.xml

@@ -136,6 +136,12 @@
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.pdfbox</groupId>
+            <artifactId>pdfbox</artifactId>
+            <version>2.0.20</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 143 - 113
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveAutoPdfServiceImpl.java

@@ -8,6 +8,9 @@ import com.itextpdf.text.pdf.*;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.util.IOUtils;
 import org.springblade.archive.entity.ArchiveFormulaConfig;
@@ -58,7 +61,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
     private ArchiveFileClient archiveFileClient;
 
-    public static final  String[] ARCHIVE_NUMBER = new String[]{"r_Archives_front","r_Archives_catalog","r_Archives_spare","r_Archives_back"};
+    public static final String[] ARCHIVE_NUMBER = new String[]{"r_Archives_front", "r_Archives_catalog", "r_Archives_spare", "r_Archives_back"};
 
     public static final Map<String, String> URL_MAP = new HashMap<>();
     public static final Map<String, String> NAME_MAP = new HashMap<>();
@@ -123,7 +126,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         List<ArchiveFile> waitFiles = new ArrayList<>();
         waitFiles.add(f1);
         waitFiles.add(f2);
-        builtFilePageNo(archivesAuto,waitFiles);
+        builtFilePageNo(archivesAuto, waitFiles);
         System.out.println();
 
 
@@ -207,20 +210,21 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
         List<ArchiveFile> archiveFiles = new ArrayList<>();
 
-        for (int i = 0; i < 20;i++) {
+        for (int i = 0; i < 20; i++) {
             archiveFiles.add(archiveFile);
         }
-        buildArchiveFrontPdfs(projectId,archivesAuto,archiveFiles,true);
+        buildArchiveFrontPdfs(projectId, archivesAuto, archiveFiles, true);
     }
 
 
     /**
-     *  生成四要素
+     * 生成四要素
+     *
      * @param projectId
-     * @param archivesAuto, 会更新起始时间和结束时间,所以调用后要更新
+     * @param archivesAuto,   会更新起始时间和结束时间,所以调用后要更新
      * @param archiveFileList
      */
-    public void buildArchiveFrontPdfs(Long projectId, ArchivesAuto archivesAuto,List<ArchiveFile> archiveFileList,
+    public void buildArchiveFrontPdfs(Long projectId, ArchivesAuto archivesAuto, List<ArchiveFile> archiveFileList,
                                       boolean bBuildFront) {
 
         if (bBuildFront == false) {
@@ -248,26 +252,26 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         String secretLevel = archivesAuto.getSecretLevel();
         String storageTime = archivesAuto.getStorageTime();
 
-        Map<String,Object> variables = dataSourceBuilder(archivesAuto,archiveFileList);
+        Map<String, Object> variables = dataSourceBuilder(archivesAuto, archiveFileList);
 
         // 使用生成的档案号码字符串链表生成档案 PDF 文件
         List<String> frontUrls = new ArrayList<>();
         List<String> backUrls = new ArrayList<>();
         for (String number : numberFronts) {
             // 具体实现省略
-            buildFrontPdf(archivesAuto,number, variables,frontUrls);
+            buildFrontPdf(archivesAuto, number, variables, frontUrls);
         }
 
         for (String number : numberBacks) {
             // 具体实现省略
-            buildFrontPdf(archivesAuto,number, variables,backUrls);
+            buildFrontPdf(archivesAuto, number, variables, backUrls);
         }
 
         //将封面写入archivesAuto
         frontUrls.addAll(backUrls);
 
         //统计文件大小
-        RefreshFileSize(archivesAuto,archiveFileList,frontUrls);
+        RefreshFileSize(archivesAuto, archiveFileList, frontUrls);
 
         String joinedUrls = String.join(", ", frontUrls);
         archivesAuto.setOutUrl(joinedUrls);
@@ -277,10 +281,11 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
     /**
      * 打码
+     *
      * @param archivesAuto
      * @param waitArchiveFiles
      */
-    public void builtFilePageNo(ArchivesAuto archivesAuto,List<ArchiveFile> waitArchiveFiles){
+    public void builtFilePageNo(ArchivesAuto archivesAuto, List<ArchiveFile> waitArchiveFiles) {
 
         Long projectId = archivesAuto.getProjectId();
 
@@ -288,7 +293,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         //是否打页码
         if (!config.isPage()) {
             //不需要打页码的,把字段pdf_page_url设为null
-            for(ArchiveFile file:waitArchiveFiles){
+            for (ArchiveFile file : waitArchiveFiles) {
                 file.setPdfPageUrl("");
             }
             return;
@@ -300,17 +305,17 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         }
 
         List<String> urls = new ArrayList<>();
-        for (ArchiveFile f: waitArchiveFiles) {
+        for (ArchiveFile f : waitArchiveFiles) {
             String url = getPdfFileUrl(f);
-            if (f.getIsElement() != null && f.getIsElement()== 1) {
+            if (f.getIsElement() != null && f.getIsElement() == 1) {
                 urls.add(FileUtils.Element_FLAG + url);
             } else {
                 urls.add(url);
             }
         }
         String localPath = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
-        List<String> pageUrls = FileUtils.doForPageNumberUseItextpdf(urls,localPath,newIOSSClient, archivesAuto.getProjectId());
-        for(int i=0;i<waitArchiveFiles.size();i++){
+        List<String> pageUrls = FileUtils.doForPageNumberUseItextpdf(urls, localPath, newIOSSClient, archivesAuto.getProjectId());
+        for (int i = 0; i < waitArchiveFiles.size(); i++) {
             waitArchiveFiles.get(i).setPdfPageUrl(pageUrls.get(i));
         }
 
@@ -318,14 +323,12 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
     }
 
 
-
     /**
-     *
-     * @param number  四要素的表名
+     * @param number    四要素的表名
      * @param variables 参数集
-     * @param urls  返回的url
+     * @param urls      返回的url
      */
-    public void buildFrontPdf(ArchivesAuto archivesAuto,String number, Map<String,Object> variables,List<String> urls) {
+    public void buildFrontPdf(ArchivesAuto archivesAuto, String number, Map<String, Object> variables, List<String> urls) {
         // Step 1: Get the list of formulas using archiveFormulaConfigService
         List<ArchiveFormulaConfig> formulaConfigs = archiveFormulaConfigService.getByNumber(number);
 
@@ -335,7 +338,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
         ArchiveFormulaConfig multiLineconfig = null;
         //采取
-        String fileName = FileUtils.generateFilename(number,0,archivesAuto.getId());
+        String fileName = FileUtils.generateFilename(number, 0, archivesAuto.getId());
 
         for (ArchiveFormulaConfig config : formulaConfigs) {
             String coords = config.getCoords();
@@ -352,14 +355,13 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
                 }
             }*/
 
-            if(variables.containsKey("ArchiveFile") && variables.get("ArchiveFile") instanceof List
-                    && formula.indexOf("ArchiveFile") >= 0){
+            if (variables.containsKey("ArchiveFile") && variables.get("ArchiveFile") instanceof List
+                    && formula.indexOf("ArchiveFile") >= 0) {
 
                 multiLineconfig = config;
                 //handleArchiveFile(coords, formula, variables, file_path, excelUrl, dataInfo,urls);
                 continue;
-            }
-            else{
+            } else {
                 handleNonArchiveFile(config, coords, formula, variables, file_path, excelUrl, dataInfo);
             }
         }
@@ -367,11 +369,11 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         if (multiLineconfig != null) {
             String coords = multiLineconfig.getCoords();
             String formula = multiLineconfig.getFormula();
-            handleArchiveFile(coords, formula, variables, file_path, excelUrl, dataInfo,urls,fileName, archivesAuto.getProjectId());
+            handleArchiveFile(coords, formula, variables, file_path, excelUrl, dataInfo, urls, fileName, archivesAuto.getProjectId());
 
-        }else {
+        } else {
             try {
-                String url = getBussPdfInfo(fileName, dataInfo, excelUrl, file_path,OssConstant.ARCHIVE_DIRECTORY,archivesAuto.getProjectId());
+                String url = getBussPdfInfo(fileName, dataInfo, excelUrl, file_path, OssConstant.ARCHIVE_DIRECTORY, archivesAuto.getProjectId());
                 urls.add(url);
             } catch (Exception e) {
                 e.printStackTrace();
@@ -382,6 +384,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
     /**
      * 生成 卷内目录
+     *
      * @param coords
      * @param formula
      * @param variables
@@ -391,8 +394,8 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
      * @param urls
      */
     private void handleArchiveFile(String coords, String formula,
-                                   Map<String,Object> variables,String file_path,
-                                   String excelUrl, Map<String, Object> dataInfo,List<String> urls,String fileName,Long projectId){
+                                   Map<String, Object> variables, String file_path,
+                                   String excelUrl, Map<String, Object> dataInfo, List<String> urls, String fileName, Long projectId) {
         //todo  目录多页合并一页,文件名带上
 
 
@@ -403,16 +406,16 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
             DataVO dataVO2 = FormulaUtil.convertCellToIndex(coordArr[1]);
             Integer pageSize = dataVO2.getY() - dataVO1.getY() + 1;
 
-            List<Map<String,Object>> archiveFiles = (List<Map<String,Object>>)variables.get("ArchiveFile");
+            List<Map<String, Object>> archiveFiles = (List<Map<String, Object>>) variables.get("ArchiveFile");
 
             Map<String, Object> pageMap = new HashMap<>();
-            if(archiveFiles != null && archiveFiles.size() > 0){
+            if (archiveFiles != null && archiveFiles.size() > 0) {
                 int pageIndex = 0; // 当前页数
                 while (true) {
-                    List<Map<String,Object>> subList = archiveFiles.subList(pageIndex * pageSize,
+                    List<Map<String, Object>> subList = archiveFiles.subList(pageIndex * pageSize,
                             Math.min((pageIndex + 1) * pageSize, archiveFiles.size()));
 
-                    if(subList.size()==0){
+                    if (subList.size() == 0) {
                         break;
                     }
 
@@ -420,12 +423,12 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
                     pageMap.putAll(dataInfo);
 
                     int subIndex = 0;
-                    for (Map<String,Object> archiveMap : subList) {
+                    for (Map<String, Object> archiveMap : subList) {
                         // 处理archiveFile逻辑
                         int y = dataVO1.getY() + subIndex;
                         List<Object> objects = FormulaUtil.expressionParseList(formula, archiveMap);
                         int xIndex = 0;
-                        for (Object o: objects) {
+                        for (Object o : objects) {
                             if (o == null) {
                                 xIndex++;
                                 continue;
@@ -439,8 +442,8 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
                         subIndex++;
                     }
                     try {
-                        Integer fileNamenum=(pageIndex * pageSize)+subIndex;
-                        String url = getBussPdfInfo(fileName + fileNamenum, pageMap, excelUrl, file_path,OssConstant.ARCHIVE_DIRECTORY,projectId);
+                        Integer fileNamenum = (pageIndex * pageSize) + subIndex;
+                        String url = getBussPdfInfo(fileName + fileNamenum, pageMap, excelUrl, file_path, OssConstant.ARCHIVE_DIRECTORY, projectId);
                         localUrls.add(url);
                     } catch (Exception e) {
                         e.printStackTrace();
@@ -464,22 +467,23 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
             FileUtils.mergePdfPublicMethods(localUrls, localPdf);
 //            BladeFile bladeFile = this.newIOSSClient.uploadFile(fileName + ".pdf", localPdf, OssConstant.ARCHIVE_DIRECTORY,projectId);
 
-            String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY,fileName,projectId);
+            String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY, fileName, projectId);
             BladeFile bladeFile = newIOSSClient.uploadFile(absoluteFileName + ".pdf", localPdf);
 
 //            ByteArrayOutputStream bos = new ByteArrayOutputStream();
 //            FileUtils.PdfCopyPublicMethods(bos, localUrls);
 //            BladeFile bladeFile = newIOSSClient.updateFile(bos.toByteArray(),fileName + ".pdf");
-            if (bladeFile!= null ) {
+            if (bladeFile != null) {
                 urls.add(bladeFile.getLink());
             }
-        }else if (localUrls.size() == 1) {
+        } else if (localUrls.size() == 1) {
             urls.add(localUrls.get(0));
         }
     }
 
     /**
      * 生成 封面,备考表,脊背
+     *
      * @param config
      * @param coords
      * @param formula
@@ -489,29 +493,29 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
      * @param dataInfo  结果集
      */
     private void handleNonArchiveFile(ArchiveFormulaConfig config, String coords, String formula,
-                                      Map<String,Object> variables,String file_path,
+                                      Map<String, Object> variables, String file_path,
                                       String excelUrl, Map<String, Object> dataInfo) {
         DataVO dataVO = FormulaUtil.convertCellToIndex(coords);
         Object object = null;
         if (formula.indexOf("~") > 0) {
             String[] formulaArr = formula.split("~");
             if (formulaArr.length == 2) {
-                Object object1 = FormulaUtil.expressionParse(formulaArr[0],variables);
-                Object object2 = FormulaUtil.expressionParse(formulaArr[1],variables);
+                Object object1 = FormulaUtil.expressionParse(formulaArr[0], variables);
+                Object object2 = FormulaUtil.expressionParse(formulaArr[1], variables);
                 object = object1 + "~" + object2;
             }
-        }else {
-            object = FormulaUtil.expressionParse(formula,variables);
+        } else {
+            object = FormulaUtil.expressionParse(formula, variables);
         }
 
 
         String key = config.getId() + "__" + dataVO.getY() + "_" + dataVO.getX();
 
 
-        if("Archive['startDate']~Archive['endDate']".equals(formula)){
-            log.info("起止时间object:"+object.toString());
-            if("null~null".equals(object)){
-                object="";
+        if ("Archive['startDate']~Archive['endDate']".equals(formula)) {
+            log.info("起止时间object:" + object.toString());
+            if ("null~null".equals(object)) {
+                object = "";
             }
         }
         dataInfo.put(key, object);
@@ -524,17 +528,18 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
     /**
      * 生成单张pdf
-     * @param fileName   文件名
+     *
+     * @param fileName  文件名
      * @param DataInfo  excel和数据
      * @param excelUrl  excel模板
-     * @param localPath  本地路径
-     * @param ossPath  oss上的路径
+     * @param localPath 本地路径
+     * @param ossPath   oss上的路径
      * @param projectId 项目ID
      * @return
      * @throws Exception
      */
-    public String getBussPdfInfo(String fileName,Map<String, Object> DataInfo,String excelUrl,String localPath,
-         String ossPath, Long projectId) throws Exception{
+    public String getBussPdfInfo(String fileName, Map<String, Object> DataInfo, String excelUrl, String localPath,
+                                 String ossPath, Long projectId) throws Exception {
 
         if (fileName == null) {
             fileName = SnowFlakeUtil.getId().toString();
@@ -550,9 +555,9 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
         // 获取excel流 和 html流
         InputStream exceInp = null;
-        if ( isOssFilePath(excelUrl)){
+        if (isOssFilePath(excelUrl)) {
             exceInp = CommonUtil.getOSSInputStream(excelUrl);
-        }else {
+        } else {
             exceInp = new FileInputStream(new File(excelUrl));
         }
 
@@ -575,12 +580,12 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
                     int x2 = 0;
                     int y2 = 0;
 
-                    if (xy.length == 2 ) {
+                    if (xy.length == 2) {
                         x1 = Integer.parseInt(xy[1]);
                         y1 = Integer.parseInt(xy[0]);
                     }
 
-                    if (xy.length == 4 ) {
+                    if (xy.length == 4) {
                         x2 = Integer.parseInt(xy[3]);
                         y2 = Integer.parseInt(xy[2]);
                     }
@@ -609,11 +614,10 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
                         pict.resize(1, 1);
                         FileUtils.imageOrientation(sheet, anchor, new DataVO(x1 - 1, y1 - 1));
 
-                    }
-                    else {
-                        Row row = sheet.getRow(y1 );
+                    } else {
+                        Row row = sheet.getRow(y1);
                         if (row != null) {
-                            Cell cell = row.getCell(x1 );
+                            Cell cell = row.getCell(x1);
                             if (cell != null || ObjectUtils.isNotEmpty(cell)) {
 //                                boolean bflag = true;
 //                                if (bflag) {
@@ -633,24 +637,25 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         FileOutputStream outputStream = new FileOutputStream(excelPath);
         workbook.write(outputStream);
         FileUtils.setExcelScaleToPdf(excelPath, localPdfPath);
-        String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY,fileName,projectId);
+        String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY, fileName, projectId);
         BladeFile bladeFile = newIOSSClient.uploadFile(absoluteFileName + ".pdf", localPdfPath);
 
         ///BladeFile bladeFile = newIOSSClient.uploadFile(fileName + ".pdf", localPdfPath,ossPath, projectId);
         String pdfLink = "";
-        if (bladeFile!= null ){
+        if (bladeFile != null) {
             pdfLink = bladeFile.getLink();
         }
         return pdfLink;
     }
 
     /**
-     *  生成四要素的数据源
+     * 生成四要素的数据源
+     *
      * @param archive
      * @param datas
      * @return
      */
-    public static  Map<String,Object> dataSourceBuilder(ArchivesAuto archive, List<ArchiveFile> datas){
+    public static Map<String, Object> dataSourceBuilder(ArchivesAuto archive, List<ArchiveFile> datas) {
 
         //预处理
         archive.setSecretLevel(FormulaUtil.securityLevelMap.get(archive.getSecretLevel()));
@@ -662,11 +667,11 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         List<Map<String, Object>> fileMapList = new ArrayList<>();
 
         //todo  增加获取总大小
-        for (ArchiveFile file:  datas) {
+        for (ArchiveFile file : datas) {
 
-            if (file.getIsElement() != null && file.getIsElement()== 1){
+            if (file.getIsElement() != null && file.getIsElement() == 1) {
 
-            }else {
+            } else {
 
                 idx++;
                 //设置序号
@@ -679,7 +684,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
                 file.setPageNum(iStartPage.toString());
 
                 //最后一页
-                if (file.getFilePage() != null ) {
+                if (file.getFilePage() != null) {
                     iStartPage += file.getFilePage();
                 }
                 if (idx >= datas.size()) {
@@ -701,7 +706,7 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
         for (ArchiveFile file : datas) {
             String fileTime = file.getFileTime();
-            if(StringUtils.isNotEmpty(fileTime)){
+            if (StringUtils.isNotEmpty(fileTime)) {
                 if (minDate.isEmpty() || fileTime.compareTo(minDate) <= 0) {
                     minDate = fileTime;
                 }
@@ -713,40 +718,41 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
         // 将日期赋值给startDate和endDate
         if (!minDate.isEmpty()) {
-            LocalDateTime localDateTime = FormulaUtil.parseStringToLocalDateTime(minDate,"yyyyMMdd");
+            LocalDateTime localDateTime = FormulaUtil.parseStringToLocalDateTime(minDate, "yyyyMMdd");
             archive.setStartDate(localDateTime);
         }
         if (!maxDate.isEmpty()) {
-            LocalDateTime localDateTime = FormulaUtil.parseStringToLocalDateTime(maxDate,"yyyyMMdd");
+            LocalDateTime localDateTime = FormulaUtil.parseStringToLocalDateTime(maxDate, "yyyyMMdd");
             archive.setEndDate(localDateTime);
         }
 
         Map<String, Object> archivesAutoMap = new ObjectMapper().convertValue(archive, Map.class);
-        if (archive.getRollDate()!= null) {
-            archivesAutoMap.put("rollDate",FormulaUtil.formatLocalDateTime(archive.getRollDate(),"yyyy年MM月dd日"));
+        if (archive.getRollDate() != null) {
+            archivesAutoMap.put("rollDate", FormulaUtil.formatLocalDateTime(archive.getRollDate(), "yyyy年MM月dd日"));
         }
 
-        if (archive.getReviewDate()!= null) {
-            archivesAutoMap.put("reviewDate",FormulaUtil.formatLocalDateTime(archive.getReviewDate(),"yyyy年MM月dd日"));
+        if (archive.getReviewDate() != null) {
+            archivesAutoMap.put("reviewDate", FormulaUtil.formatLocalDateTime(archive.getReviewDate(), "yyyy年MM月dd日"));
         }
 
-        if (archive.getStartDate()!= null) {
-            archivesAutoMap.put("startDate",FormulaUtil.formatLocalDateTime(archive.getStartDate(),"yyyyMMdd"));
+        if (archive.getStartDate() != null) {
+            archivesAutoMap.put("startDate", FormulaUtil.formatLocalDateTime(archive.getStartDate(), "yyyyMMdd"));
         }
 
-        if (archive.getEndDate()!= null) {
-            archivesAutoMap.put("endDate",FormulaUtil.formatLocalDateTime(archive.getEndDate(),"yyyyMMdd"));
+        if (archive.getEndDate() != null) {
+            archivesAutoMap.put("endDate", FormulaUtil.formatLocalDateTime(archive.getEndDate(), "yyyyMMdd"));
         }
 
-        Map<String,Object> variables = new HashMap<>();
-        variables.put("Archive",archivesAutoMap);
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("Archive", archivesAutoMap);
 
-        variables.put("ArchiveFile",fileMapList);
-        return  variables;
+        variables.put("ArchiveFile", fileMapList);
+        return variables;
     }
 
     /**
      * 获取四要素模板的url,这里写死,后续可以从清表的 ”归档“模板树下获取
+     *
      * @param number
      * @return
      */
@@ -758,15 +764,16 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
     /**
      * 获取指定文件的pdf文件
+     *
      * @param file
      * @return
      */
-    public String getPdfFileUrl(ArchiveFile file){
+    public String getPdfFileUrl(ArchiveFile file) {
         //
         String url = file.getPdfFileUrl();
         if (StringUtil.isEmpty(url)) {
             String fileUrl = file.getFileUrl();
-            if(fileUrl.endsWith(".pdf") || fileUrl.endsWith(".PDF")){
+            if (fileUrl.endsWith(".pdf") || fileUrl.endsWith(".PDF")) {
                 url = file.getFileUrl();
             }
         }
@@ -779,23 +786,24 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
     /**
      * 刷新文件大小
+     *
      * @param archive
      * @param datas
      * @param frontUrls
      */
-    public void RefreshFileSize(ArchivesAuto archive,List<ArchiveFile> datas,List<String> frontUrls){
+    public void RefreshFileSize(ArchivesAuto archive, List<ArchiveFile> datas, List<String> frontUrls) {
 
         List<String> fileUrls = new ArrayList<>();
-        for (ArchiveFile file: datas) {
+        for (ArchiveFile file : datas) {
             String url = getPdfFileUrl(file);
-            if(StringUtils.isEmpty(url)){
+            if (StringUtils.isEmpty(url)) {
                 continue;
             }
             fileUrls.add(url);
         }
 
         fileUrls.addAll(frontUrls);
-        List<FileSize>  fileSizes = org.springblade.common.utils.FileUtils.getOssFileSize(fileUrls);
+        List<FileSize> fileSizes = org.springblade.common.utils.FileUtils.getOssFileSize(fileUrls);
 
         double totalSize = fileSizes.stream()
                 .mapToDouble(FileSize::getFileSize)
@@ -805,9 +813,9 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
         //todo 生成相册内容,待补充
         int i = 0;
-        for (ArchiveFile file: datas) {
+        for (ArchiveFile file : datas) {
             double size = fileSizes.get(i).getFileSize();
-            if (file.getFileSize()!= null) {
+            if (file.getFileSize() != null) {
                 file.setFileSize(Math.round(size));
             }
         }
@@ -815,10 +823,11 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
     /**
      * 刷新档号
+     *
      * @param archive
      * @param fileNumber
      */
-    public boolean refreshFileNumber(ArchivesAuto archive,String fileNumber) {
+    public boolean refreshFileNumber(ArchivesAuto archive, String fileNumber) {
         //没变化则不用刷新
         if (fileNumber.equals(archive.getFileNumber())) {
             return false;
@@ -829,42 +838,44 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
 
         List<ArchiveFile> archiveFiles = archiveFileClient.getArchiveFileByArchiveID(archive.getId());
 
-        buildArchiveFrontPdfs(projectId,archive,archiveFiles,true);
+        buildArchiveFrontPdfs(projectId, archive, archiveFiles, true);
 
         return true;
     }
 
     /**
      * 刷新档号
+     *
      * @param archive
      * @param fileNumber
      */
-    public boolean refreshFileNumberForce(ArchivesAuto archive,String fileNumber) {
+    public boolean refreshFileNumberForce(ArchivesAuto archive, String fileNumber) {
         //没变化则不用刷新,强制刷新
         Long projectId = archive.getProjectId();
         archive.setFileNumber(fileNumber);
 
         List<ArchiveFile> archiveFiles = archiveFileClient.getArchiveFileByArchiveID(archive.getId());
 
-        buildArchiveFrontPdfs(projectId,archive,archiveFiles,true);
+        buildArchiveFrontPdfs(projectId, archive, archiveFiles, true);
 
         return true;
     }
 
     /**
      * 合并pdf并上传到oss
+     *
      * @param urlList
      * @param fileName
      * @return
      */
-    public String MergePdfAndUpload(List<String> urlList,String fileName,String filePath,Long pojectId) {
-       String url = "";
-       Long id = SnowFlakeUtil.getId();
-       String localPdf = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id + ".pdf";
+    public String MergePdfAndUpload(List<String> urlList, String fileName, String filePath, Long pojectId) {
+        String url = "";
+        Long id = SnowFlakeUtil.getId();
+        String localPdf = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id + ".pdf";
 
-       try {
+        try {
             //合并pdf
-            FileUtils.mergePdfPublicMethods(urlList,localPdf);
+            FileUtils.mergePdfPublicMethods(urlList, localPdf);
 
             if (StringUtils.isEmpty(filePath)) {
                 filePath = OssConstant.TEMP_DIRECTORY;
@@ -873,8 +884,8 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
             fileName += (OssConstant.SEPARATOR + id);
 
             //上传到oss
-           String absoluteFileName = FileUtils.getOssPath(OssConstant.TEMP_DIRECTORY,fileName,null);
-           BladeFile file = newIOSSClient.uploadFile(absoluteFileName + ".pdf", localPdf);
+            String absoluteFileName = FileUtils.getOssPath(OssConstant.TEMP_DIRECTORY, fileName, null);
+            BladeFile file = newIOSSClient.uploadFile(absoluteFileName + ".pdf", localPdf);
 
 
 //            BladeFile file  = newIOSSClient.uploadFile(fileName+ ".pdf", localPdf,filePath,pojectId);
@@ -886,22 +897,23 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
     }
 
     @Override
-    public String upFile(InputStream inputStream,Long projectId) {
+    public String upFile(InputStream inputStream, Long projectId) {
         String url = "";
         Long id = SnowFlakeUtil.getId();
         String localPdf = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id + ".pdf";
         String fileName = id + ".pdf";
         try {
-            //合并pdf
+            //合并PDF
             byte[] bytes = FileUtils.InputStreamToBytes(inputStream);
             OutputStream outputStream = new FileOutputStream(localPdf);
             outputStream.write(bytes);
 
-            //上传到oss
-            String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY,fileName,projectId);
+            //将PDF设置为A4纸大小
+            this.setPdfToA4Size(localPdf, localPdf);
 
+            //上传到OSS
+            String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY, fileName, projectId);
             BladeFile file = newIOSSClient.uploadFile(absoluteFileName, localPdf);
-
             url = file.getLink();
         } catch (Exception e) {
             e.printStackTrace();
@@ -909,6 +921,24 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
         return url;
     }
 
+    /**
+     * 设置pdf大小为A4纸大小
+     *
+     * @param inputPdfPath
+     * @param outputPdfPath
+     */
+    private void setPdfToA4Size(String inputPdfPath, String outputPdfPath) {
+        try {
+            PDDocument document = PDDocument.load(new File(inputPdfPath));
+            PDPage newPage = new PDPage(PDRectangle.A4);
+            document.removePage(0);
+            document.addPage(newPage);
+            document.save(outputPdfPath);
+            document.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
 
 }