liuyc 1 year ago
parent
commit
8451bad2c8

+ 20 - 4
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchiveAutoPdfServiceImpl.java

@@ -22,6 +22,7 @@ import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.constant.OssConstant;
 import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
+import org.springblade.common.utils.SystemUtils;
 import org.springblade.common.vo.DataVO;
 import org.springblade.common.vo.FileSize;
 import org.springblade.core.oss.model.BladeFile;
@@ -895,21 +896,27 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
     public String upFile(InputStream inputStream, Long projectId) {
         String url = "";
         Long id = SnowFlakeUtil.getId();
-        String localPdf = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id + ".pdf";
+        Long id1 = SnowFlakeUtil.getId();
+        String localPdfIn = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id + ".pdf";
+        String localPdfOut = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL) + "/pdf/" + id1 + ".pdf";
+        if (SystemUtils.isWindows()) {
+            localPdfIn = "c://upload/pdf/" + id + ".pdf";
+            localPdfOut = "c://upload/pdf/" + id1 + ".pdf";
+        }
         String fileName = id + ".pdf";
         OutputStream outputStream = null;
         try {
             //合并PDF
             byte[] bytes = FileUtils.InputStreamToBytes(inputStream);
-            outputStream = new FileOutputStream(localPdf);
+            outputStream = new FileOutputStream(localPdfIn);
             outputStream.write(bytes);
 
             //设置PDF每页大小为A4,内容等比缩放,方向同步
-            //PdfResizeTool.resizeToA4WithContentScaling(localPdf, localPdf);
+            PdfResizeTool.resizeToA4WithContentScaling(localPdfIn, localPdfOut);
 
             //上传到OSS
             String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY, fileName, projectId);
-            BladeFile file = newIOSSClient.uploadFile(absoluteFileName, localPdf);
+            BladeFile file = newIOSSClient.uploadFile(absoluteFileName, localPdfOut);
             url = file.getLink();
         } catch (Exception e) {
             e.printStackTrace();
@@ -919,6 +926,15 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
                 if (outputStream != null) {
                     outputStream.close();
                 }
+                //删除临时文件
+                File localPdfInFile = new File(localPdfIn);
+                if (localPdfInFile.exists()) {
+                    localPdfInFile.delete();
+                }
+                File localPdfOutFile = new File(localPdfOut);
+                if (localPdfOutFile.exists()) {
+                    localPdfOutFile.delete();
+                }
             } catch (IOException ex) {
                 ex.printStackTrace();
             }

+ 4 - 3
blade-service/blade-archive/src/main/java/org/springblade/archive/utils/PdfResizeTool.java

@@ -5,9 +5,9 @@ import com.itextpdf.kernel.geom.Rectangle;
 import com.itextpdf.kernel.pdf.*;
 import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
 
-
 import java.io.IOException;
 
+
 public class PdfResizeTool {
 
     /**
@@ -54,9 +54,10 @@ public class PdfResizeTool {
         outputDocument.close();
     }
 
-    /*public static void main(String[] args) throws IOException {
+
+    /*public static void main(String[] args) throws Exception {
         String inputPdfPath = "D:\\Download\\66666.pdf";
-        String outputPdfPath = "D:\\Download\\6666611111.pdf";
+        String outputPdfPath = "D:\\Download\\AAAAAAA.pdf";
         resizeToA4WithContentScaling(inputPdfPath, outputPdfPath);
     }*/