word转pdf #286
@@ -183,3 +183,15 @@ imConfig:
|
|||||||
secretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv
|
secretId: AKID3xfHgroY4MQHvLXUXMwIQL1UjmbBX1Tv
|
||||||
# 腾讯云密钥
|
# 腾讯云密钥
|
||||||
secretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7
|
secretKey: INDrIXcT8YmomZBcsy0oNirnU0LTN4X7
|
||||||
|
jodconverter:
|
||||||
|
local:
|
||||||
|
#暂时关闭预览,启动时会有点慢
|
||||||
|
enabled: true
|
||||||
|
#设置libreoffice主目录 linux地址如:/usr/lib64/libreoffice
|
||||||
|
office-home: /usr/lib64/libreoffice
|
||||||
|
# office-home: D:/Program Files/LibreOffice
|
||||||
|
# office-home: D:\app\libreOffice
|
||||||
|
#开启多个libreoffice进程,每个端口对应一个进程
|
||||||
|
port-numbers: 8100
|
||||||
|
#libreoffice进程重启前的最大进程数
|
||||||
|
max-tasks-per-process: 100
|
||||||
|
|||||||
@@ -11,12 +11,57 @@
|
|||||||
|
|
||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
|
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
common通用工具
|
common通用工具
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jodconverter</groupId>
|
||||||
|
<artifactId>jodconverter-core</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jodconverter</groupId>
|
||||||
|
<artifactId>jodconverter-local</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jodconverter</groupId>
|
||||||
|
<artifactId>jodconverter-spring-boot-starter</artifactId>
|
||||||
|
<version>4.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.artofsolving</groupId>
|
||||||
|
<artifactId>jodconverter</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openoffice</groupId>
|
||||||
|
<artifactId>jurt</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openoffice</groupId>
|
||||||
|
<artifactId>ridl</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openoffice</groupId>
|
||||||
|
<artifactId>juh</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openoffice</groupId>
|
||||||
|
<artifactId>unoil</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Spring框架基本的核心工具 -->
|
<!-- Spring框架基本的核心工具 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
|
||||||
|
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.ruoyi.common.exception.ServiceException;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jodconverter.document.DocumentFormat;
|
||||||
|
import org.jodconverter.office.OfficeException;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LibreOffice工具类,用于将word,excel,ppt等格式文件转为pdf预览
|
||||||
|
*
|
||||||
|
* @author xuyuxiang
|
||||||
|
* @date 2020/7/6 14:55
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class LibreOfficeUtil {
|
||||||
|
@Value("${jodconverter.local.office-home}")
|
||||||
|
private long OpenOffice_HOME;
|
||||||
|
|
||||||
|
private static DocumentConverter documentConverter;
|
||||||
|
|
||||||
|
private static void init() {
|
||||||
|
try {
|
||||||
|
documentConverter = SpringUtil.getBean(DocumentConverter.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ServiceException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean doc2pdf(File docFile, File pdfFile) {
|
||||||
|
boolean result = false;// 转换结果
|
||||||
|
if (docFile.exists()) {
|
||||||
|
if (!pdfFile.exists()) {
|
||||||
|
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
|
||||||
|
try {
|
||||||
|
connection.connect();
|
||||||
|
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
|
||||||
|
converter.convert(docFile, pdfFile);
|
||||||
|
// 关闭连接
|
||||||
|
connection.disconnect();
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
log.info("****pdf转换成功,PDF输出:" + pdfFile.getPath() + "****");
|
||||||
|
} catch (java.net.ConnectException e) {
|
||||||
|
log.error("openoffice服务未启动", e);
|
||||||
|
} catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
|
||||||
|
log.error("读取转换文件失败", e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("转换失败", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = true;
|
||||||
|
log.info("****已经转换为pdf,不需要再进行转化****");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("****需要转换的文档不存在,无法转换****");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* doc转pdf(程序启动openoffice)
|
||||||
|
*
|
||||||
|
* @param inputFile 输入文件
|
||||||
|
* @param outputFile 输出文件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean doc2pdf2(File inputFile, File outputFile) {
|
||||||
|
boolean result = false;
|
||||||
|
// OpenOffice的安装目录
|
||||||
|
String OpenOffice_HOME = "D:\\app\\libreOffice";
|
||||||
|
if (OpenOffice_HOME.charAt(OpenOffice_HOME.length() - 1) != '/') {
|
||||||
|
OpenOffice_HOME += "/";
|
||||||
|
}
|
||||||
|
Process process = null;
|
||||||
|
try {
|
||||||
|
// 启动OpenOffice的服务
|
||||||
|
String command = OpenOffice_HOME
|
||||||
|
+ "program/soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\"";
|
||||||
|
process = Runtime.getRuntime().exec(command);
|
||||||
|
// 连接 OpenOffice实例,运行在8100端口
|
||||||
|
OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
// 转换
|
||||||
|
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
|
||||||
|
converter.convert(inputFile, outputFile);
|
||||||
|
|
||||||
|
// 关闭连接
|
||||||
|
connection.disconnect();
|
||||||
|
// 销毁OpenOffice服务的进程
|
||||||
|
process.destroy();
|
||||||
|
|
||||||
|
log.info("****pdf转换成功,PDF输出:" + outputFile.getPath() + "****");
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("pdf转换失败", e);
|
||||||
|
} finally {
|
||||||
|
if (process != null) {
|
||||||
|
process.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+25
-13
@@ -180,7 +180,16 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
|||||||
//
|
//
|
||||||
for (String bookmark : bookmarkList) {
|
for (String bookmark : bookmarkList) {
|
||||||
if(columnValueMap.containsKey(bookmark)){
|
if(columnValueMap.containsKey(bookmark)){
|
||||||
datas.put(bookmark,columnValueMap.get(bookmark));
|
if(bookmark.equals("resSex")){
|
||||||
|
String responSex = columnValueMap.get(bookmark);
|
||||||
|
if (responSex.equals("0")) {
|
||||||
|
datas.put(bookmark, "男");
|
||||||
|
} else {
|
||||||
|
datas.put(bookmark, "女");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
datas.put(bookmark, columnValueMap.get(bookmark));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
@@ -231,11 +240,11 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
|||||||
// todo 线上仲裁/线下仲裁方式未选择
|
// todo 线上仲裁/线下仲裁方式未选择
|
||||||
//线上开庭时
|
//线上开庭时
|
||||||
if (arbitratMethod == 1) {
|
if (arbitratMethod == 1) {
|
||||||
String replace = onLine.replace(onLineDate, hearDateStr);
|
String replace = onLine.replace(onLineDate, Optional.ofNullable(hearDateStr).orElse(""));
|
||||||
datas.put("onLine", replace);
|
datas.put("onLine", replace);
|
||||||
} else {
|
} else {
|
||||||
//书面仲裁时
|
//书面仲裁时
|
||||||
String replace = written.replace(writtenDate, hearDateStr);
|
String replace = written.replace(writtenDate, Optional.ofNullable(hearDateStr).orElse(""));
|
||||||
datas.put("written", replace);
|
datas.put("written", replace);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -252,7 +261,7 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
|||||||
if (arbitratMethod == 1) {
|
if (arbitratMethod == 1) {
|
||||||
if (isAbsence != null && isAbsence == 1) {
|
if (isAbsence != null && isAbsence == 1) {
|
||||||
// 被申请人缺席
|
// 被申请人缺席
|
||||||
String absentReplace = absent.replace("{{agentName}}", agentName);
|
String absentReplace = absent.replace("{{agentName}}", Optional.ofNullable(agentName).orElse(""));
|
||||||
datas.put("absent",absentReplace);
|
datas.put("absent",absentReplace);
|
||||||
// 被申请人缺席
|
// 被申请人缺席
|
||||||
String resAbsentReplace=resAbsent;
|
String resAbsentReplace=resAbsent;
|
||||||
@@ -267,7 +276,7 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
|||||||
datas.put("resAbsent",resAbsentReplace);
|
datas.put("resAbsent",resAbsentReplace);
|
||||||
} else {
|
} else {
|
||||||
// 出席
|
// 出席
|
||||||
String attendReplace = attend.replace("{{agentName}}", agentName);
|
String attendReplace = attend.replace("{{agentName}}", Optional.ofNullable(agentName).orElse(""));
|
||||||
datas.put("attend",attend);
|
datas.put("attend",attend);
|
||||||
// 被申请人证据
|
// 被申请人证据
|
||||||
if(caseAttachMap!=null && CollectionUtil.isNotEmpty(caseAttachMap.get(6))){
|
if(caseAttachMap!=null && CollectionUtil.isNotEmpty(caseAttachMap.get(6))){
|
||||||
@@ -281,7 +290,7 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
|||||||
for (CaseAttach caseAttach : caseAttaches) {
|
for (CaseAttach caseAttach : caseAttaches) {
|
||||||
stringBuilder.append(caseAttach.getAnnexName()).append("\n");
|
stringBuilder.append(caseAttach.getAnnexName()).append("\n");
|
||||||
}
|
}
|
||||||
resFileRplace = resFile.replace("{{resFile}}", stringBuilder.toString()).replace("{{applicantOpinion}}", arbitrateRecordSelect.getApplicantOpinion());
|
resFileRplace = resFile.replace("{{resFile}}", stringBuilder.toString()).replace("{{applicantOpinion}}", Optional.ofNullable(arbitrateRecordSelect.getApplicantOpinion()).orElse(""));
|
||||||
}
|
}
|
||||||
datas.put("resFile",resFileRplace);
|
datas.put("resFile",resFileRplace);
|
||||||
}else {
|
}else {
|
||||||
@@ -296,7 +305,7 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
|||||||
for (CaseAttach caseAttach : caseAttaches) {
|
for (CaseAttach caseAttach : caseAttaches) {
|
||||||
stringBuilder.append(caseAttach.getAnnexName()).append("\n");
|
stringBuilder.append(caseAttach.getAnnexName()).append("\n");
|
||||||
}
|
}
|
||||||
resAttendOpinionReplace = resAttendOpinion.replace("{{applicantFile}}", stringBuilder.toString()).replace("{{respondentOpinion}}", arbitrateRecordSelect.getRespondentOpinion());
|
resAttendOpinionReplace = resAttendOpinion.replace("{{applicantFile}}", stringBuilder.toString()).replace("{{respondentOpinion}}", arbitrateRecordSelect.getRespondentOpinion()==null?"":arbitrateRecordSelect.getRespondentOpinion());
|
||||||
}
|
}
|
||||||
|
|
||||||
datas.put("resAttendOpinion",resAttendOpinionReplace);
|
datas.put("resAttendOpinion",resAttendOpinionReplace);
|
||||||
@@ -306,13 +315,16 @@ public class AdjudicationServiceImpl implements IAdjudicationService {
|
|||||||
|
|
||||||
String month = String.format("%02d", now.getMonthValue());
|
String month = String.format("%02d", now.getMonthValue());
|
||||||
String day = String.format("%02d", now.getDayOfMonth());
|
String day = String.format("%02d", now.getDayOfMonth());
|
||||||
String modalFilePath = "/data/arbitrate-document/template/新裁决书模板.docx";
|
// todo
|
||||||
// String modalFilePath = "D:/新裁决书模板.docx";
|
// String modalFilePath = "/data/arbitrate-document/template/新裁决书模板.docx";
|
||||||
// todo 服务器路径
|
String modalFilePath = templatePath;
|
||||||
String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
|
// todo
|
||||||
// String saveFolderPath = "D:/";
|
// String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
|
||||||
|
String saveFolderPath = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
|
||||||
String fileName = UUID.randomUUID().toString().replace("-", "") + ".docx";
|
String fileName = UUID.randomUUID().toString().replace("-", "") + ".docx";
|
||||||
String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
|
// todo
|
||||||
|
// String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
|
||||||
|
String saveName = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day + "/" + fileName;
|
||||||
String resultFilePath = saveFolderPath + "/" + fileName;
|
String resultFilePath = saveFolderPath + "/" + fileName;
|
||||||
// 创建日期目录
|
// 创建日期目录
|
||||||
File saveFolder = new File(saveFolderPath);
|
File saveFolder = new File(saveFolderPath);
|
||||||
|
|||||||
+12
-8
@@ -3016,7 +3016,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|||||||
if (unzipSuccess) {
|
if (unzipSuccess) {
|
||||||
// 查询抓取规则
|
// 查询抓取规则
|
||||||
// todo 批次需要再上传压缩包时用户填写
|
// todo 批次需要再上传压缩包时用户填写
|
||||||
List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(17L);
|
List<FatchRule> fatchRuleList = fatchRuleMapper.listByTemplateId(18L);
|
||||||
if (CollectionUtil.isEmpty(fatchRuleList)) {
|
if (CollectionUtil.isEmpty(fatchRuleList)) {
|
||||||
return error("未设置抓取规则");
|
return error("未设置抓取规则");
|
||||||
}
|
}
|
||||||
@@ -3291,7 +3291,7 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|||||||
//文件转成base64
|
//文件转成base64
|
||||||
String base64 = OCRUtils.pdfConvertBase64(pdfUrl);
|
String base64 = OCRUtils.pdfConvertBase64(pdfUrl);
|
||||||
if (base64 == null) {
|
if (base64 == null) {
|
||||||
throw new ServiceException("文件转成base64,转码失败");
|
throw new ServiceException("文件转成base64,转码失败pdfUrl:"+pdfUrl);
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
|
StringBuilder ocrText = new StringBuilder(); // 创建一个StringBuilder对象
|
||||||
@@ -3468,12 +3468,16 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|||||||
File outputFile = new File(pdfFilePath);
|
File outputFile = new File(pdfFilePath);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream docxInputStream = new FileInputStream(inputWord);
|
LibreOfficeUtil.doc2pdf2(inputWord,outputFile);
|
||||||
OutputStream outputStream = new FileOutputStream(outputFile);
|
|
||||||
IConverter converter = LocalConverter.builder().build();
|
|
||||||
converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
|
//
|
||||||
docxInputStream.close();
|
// InputStream docxInputStream = new FileInputStream(inputWord);
|
||||||
outputStream.close();
|
// OutputStream outputStream = new FileOutputStream(outputFile);
|
||||||
|
// IConverter converter = LocalConverter.builder().build();
|
||||||
|
// converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
|
||||||
|
// docxInputStream.close();
|
||||||
|
// outputStream.close();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException(e.getMessage()+"wordFilePath:"+wordFilePath+"pdfFilePath:"+pdfFilePath);
|
throw new ServiceException(e.getMessage()+"wordFilePath:"+wordFilePath+"pdfFilePath:"+pdfFilePath);
|
||||||
|
|||||||
@@ -1432,7 +1432,7 @@
|
|||||||
c.disputes,
|
c.disputes,
|
||||||
c.loan_type,
|
c.loan_type,
|
||||||
c.loan_term,
|
c.loan_term,
|
||||||
c.mediation_agreement
|
c.mediation_agreement,c.template_id templateId
|
||||||
from case_application c
|
from case_application c
|
||||||
LEFT JOIN case_affiliate ca ON ca.case_appli_id = c.id and ca.identity_type=1
|
LEFT JOIN case_affiliate ca ON ca.case_appli_id = c.id and ca.identity_type=1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user