xiongzhu %!s(int64=4) %!d(string=hai) anos
pai
achega
31304ac2e4

+ 6 - 1
src/main/java/com/izouma/awesomeAdmin/web/Word2PDFController.java

@@ -27,12 +27,13 @@ public class Word2PDFController {
         log.info("开始转换");
         log.info("开始转换");
         // 开始时间
         // 开始时间
         long start = System.currentTimeMillis();
         long start = System.currentTimeMillis();
+        ActiveXComponent app = null;
         try {
         try {
             File word = TempFile.createTempFile("word2pdf", FileUtils.getExtension(file.getOriginalFilename()));
             File word = TempFile.createTempFile("word2pdf", FileUtils.getExtension(file.getOriginalFilename()));
             File target = TempFile.createTempFile("word2pdf", ".pdf");
             File target = TempFile.createTempFile("word2pdf", ".pdf");
             FileUtils.write(file.getInputStream(), word);
             FileUtils.write(file.getInputStream(), word);
 
 
-            ActiveXComponent app = new ActiveXComponent("Word.Application");
+            app = new ActiveXComponent("Word.Application");
             Dispatch documents = app.getProperty("Documents").toDispatch();
             Dispatch documents = app.getProperty("Documents").toDispatch();
             System.out.println("打开文件: " + word.getPath());
             System.out.println("打开文件: " + word.getPath());
             Dispatch document = Dispatch.call(documents, "Open", word.getPath(), false, true).toDispatch();
             Dispatch document = Dispatch.call(documents, "Open", word.getPath(), false, true).toDispatch();
@@ -49,6 +50,10 @@ public class Word2PDFController {
         } catch (Exception e) {
         } catch (Exception e) {
             log.error("转换失败", e);
             log.error("转换失败", e);
             throw new BusinessException("转换失败" + e.getMessage());
             throw new BusinessException("转换失败" + e.getMessage());
+        } finally {
+            if (app != null) {
+                app.invoke("Quit", 0);
+            }
         }
         }
     }
     }
 }
 }