|
@@ -1,31 +1,17 @@
|
|
|
package com.ruoyi.project.common.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.artofsolving.jodconverter.DocumentConverter;
|
|
|
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
|
|
|
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
|
|
|
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
|
|
|
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.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.PdfOptions;
|
|
|
import io.jsonwebtoken.lang.Assert;
|
|
|
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.multipart.MultipartFile;
|
|
|
-
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
@@ -33,7 +19,7 @@ import java.io.OutputStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
+
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -67,13 +53,6 @@ public class WordController extends BaseController
|
|
|
// 读取模板渲染参数
|
|
|
InputStream is = getClass().getClassLoader().getResourceAsStream(templatePath);
|
|
|
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 {
|
|
|
// 将模板参数写入路径
|
|
|
template.writeToFile(filePath);
|
|
@@ -88,7 +67,6 @@ public class WordController extends BaseController
|
|
|
/**
|
|
|
* 通用附件上传
|
|
|
*/
|
|
|
- @Log(title = "通用附件上传", businessType = BusinessType.UPDATE)
|
|
|
@GetMapping("/createWord")
|
|
|
public AjaxResult word() throws IOException
|
|
|
{
|
|
@@ -102,28 +80,28 @@ public class WordController extends BaseController
|
|
|
// 生成word的路径
|
|
|
String fileDir = "D:/ticket/demo";
|
|
|
// 生成word的文件
|
|
|
- String fileName = "zszxz.docx";
|
|
|
+ String fileName = "zszxz.doc";
|
|
|
String wordPath = createWord(templatePath, fileDir, fileName, params);
|
|
|
|
|
|
try {
|
|
|
|
|
|
//读取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) {
|
|
|
e.printStackTrace();
|
|
|
}
|