ly 3 年之前
父节点
当前提交
315abc8417
共有 2 个文件被更改,包括 23 次插入43 次删除
  1. 5 3
      master/pom.xml
  2. 18 40
      master/src/main/java/com/ruoyi/project/common/controller/WordController.java

+ 5 - 3
master/pom.xml

@@ -312,11 +312,13 @@
 			<artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
 			<artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
 			<version>2.0.2</version>
 			<version>2.0.2</version>
 		</dependency>
 		</dependency>
-		<!-- https://mvnrepository.com/artifact/com.artofsolving/jodconverter-maven-plugin -->
+		<!-- https://mvnrepository.com/artifact/com.artofsolving/jodconverter -->
 		<dependency>
 		<dependency>
 			<groupId>com.artofsolving</groupId>
 			<groupId>com.artofsolving</groupId>
-			<artifactId>jodconverter-maven-plugin</artifactId>
-			<version>2.2.1</version></dependency>
+			<artifactId>jodconverter</artifactId>
+			<version>2.2.1</version>
+		</dependency>
+
 		<!--<dependency>
 		<!--<dependency>
 			<groupId>org.apache.poi</groupId>
 			<groupId>org.apache.poi</groupId>
 			<artifactId>poi-ooxml</artifactId>
 			<artifactId>poi-ooxml</artifactId>

+ 18 - 40
master/src/main/java/com/ruoyi/project/common/controller/WordController.java

@@ -1,31 +1,17 @@
 package com.ruoyi.project.common.controller;
 package com.ruoyi.project.common.controller;
 
 
-import com.alibaba.fastjson.JSON;
 import com.artofsolving.jodconverter.DocumentConverter;
 import com.artofsolving.jodconverter.DocumentConverter;
 import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
 import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
 import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
 import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
 import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
 import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
 import com.deepoove.poi.XWPFTemplate;
 import com.deepoove.poi.XWPFTemplate;
-import com.ruoyi.common.utils.file.FileUploadUtils;
-import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.framework.aspectj.lang.annotation.Log;
-import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.framework.config.RuoYiConfig;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.framework.web.domain.AjaxResult;
-import com.ruoyi.framework.web.page.TableDataInfo;
-import com.ruoyi.project.common.domain.TCommonfile;
-import com.ruoyi.project.common.service.ITCommonfileService;
 import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
 import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
 import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
 import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
 import io.jsonwebtoken.lang.Assert;
 import io.jsonwebtoken.lang.Assert;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStream;
@@ -33,7 +19,7 @@ import java.io.OutputStream;
 import java.nio.file.Files;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.Paths;
 import java.util.HashMap;
 import java.util.HashMap;
-import java.util.List;
+
 import java.util.Map;
 import java.util.Map;
 
 
 /**
 /**
@@ -67,13 +53,6 @@ public class WordController extends BaseController
         // 读取模板渲染参数
         // 读取模板渲染参数
         InputStream is = getClass().getClassLoader().getResourceAsStream(templatePath);
         InputStream is = getClass().getClassLoader().getResourceAsStream(templatePath);
         XWPFTemplate template = XWPFTemplate.compile(is).render(paramMap);
         XWPFTemplate template = XWPFTemplate.compile(is).render(paramMap);
-        //将word转成pdf
-//        PdfOptions options = PdfOptions.create();
-//        try (OutputStream outPDF = Files.newOutputStream(Paths.get("D:/ticket/demo/tes2.pdf"))) {
-//            PdfConverter.getInstance().convert(template.getXWPFDocument(), outPDF, options);
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
         try {
         try {
             // 将模板参数写入路径
             // 将模板参数写入路径
             template.writeToFile(filePath);
             template.writeToFile(filePath);
@@ -88,7 +67,6 @@ public class WordController extends BaseController
     /**
     /**
      * 通用附件上传
      * 通用附件上传
      */
      */
-    @Log(title = "通用附件上传", businessType = BusinessType.UPDATE)
     @GetMapping("/createWord")
     @GetMapping("/createWord")
     public AjaxResult word() throws IOException
     public AjaxResult word() throws IOException
     {
     {
@@ -102,28 +80,28 @@ public class WordController extends BaseController
         // 生成word的路径
         // 生成word的路径
         String fileDir = "D:/ticket/demo";
         String fileDir = "D:/ticket/demo";
         // 生成word的文件
         // 生成word的文件
-        String fileName = "zszxz.docx";
+        String fileName = "zszxz.doc";
         String wordPath = createWord(templatePath, fileDir, fileName, params);
         String wordPath = createWord(templatePath, fileDir, fileName, params);
 
 
         try {
         try {
 
 
             //读取word文档
             //读取word文档
-//            XWPFDocument document = null;
-//            try (InputStream in = Files.newInputStream(Paths.get("D:/ticket/demo/zszxz.docx"))) {
-//                document = new XWPFDocument(in);
-//            } catch (IOException e) {
-//                e.printStackTrace();
-//            }
-             //将word转成pdf
-//            PdfOptions options = PdfOptions.create();
-//            try (OutputStream outPDF = Files.newOutputStream(Paths.get("D:/ticket/demo/tes2.pdf"))) {
-//                PdfConverter.getInstance().convert(document, outPDF, options);
-//            } catch (IOException e) {
-//                e.printStackTrace();
-//            }
-            String srcPath = "D:/ticket/demo/zszxz.docx";
-            String desPath = "D:/ticket/demo/tes2.pdf";
-            Word2Pdf(srcPath, desPath);
+            XWPFDocument document = null;
+            try (InputStream in = Files.newInputStream(Paths.get("D:/ticket/demo/sems.docx"))) {
+                document = new XWPFDocument(in);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+//             将word转成pdf
+            PdfOptions options = PdfOptions.create();
+            try (OutputStream outPDF = Files.newOutputStream(Paths.get("D:/ticket/demo/tes12.pdf"))) {
+                PdfConverter.getInstance().convert(document, outPDF, options);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            String srcPath = "D:/ticket/demo/sems.doc";
+            String desPath = "D:/ticket/demo/test2.pdf";
+//            Word2Pdf(srcPath, desPath);
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
         }
         }