Merge remote-tracking branch 'origin/develop_master' into develop_3

This commit is contained in:
zhaokaiyao@91isoft.com
2021-08-31 21:39:44 +08:00
5 changed files with 84 additions and 41 deletions
+17 -9
View File
@@ -24,32 +24,40 @@
</dependency>
<!-- openOffice 和 jobconverter-->
<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<scope>system</scope>
<version>2.2.2</version>
<systemPath>${basedir}/src/main/lib/jodconverter-2.2.2.jar</systemPath>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-core</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-spring-boot-starter</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local</artifactId>
<version>4.2.2</version>
</dependency>
<!-- openOffice end-->
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>juh</artifactId>
<version>3.0.1</version>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>jurt</artifactId>
<version>3.0.1</version>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>ridl</artifactId>
<version>3.0.1</version>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>unoil</artifactId>
<version>3.0.1</version>
<version>4.1.2</version>
</dependency>
<!--OFFICE CONVERTER END-->
@@ -1,20 +1,23 @@
package com.adc.da.convert.common;
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.artofsolving.jodconverter.openoffice.converter.StreamOpenOfficeDocumentConverter;
import org.apache.commons.lang.StringUtils;
import org.jodconverter.DocumentConverter;
import org.jodconverter.JodConverter;
import org.jodconverter.OfficeDocumentConverter;
import org.jodconverter.document.DefaultDocumentFormatRegistry;
import org.jodconverter.office.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.*;
public class DocConverterPdf {
private static final Logger logger = LoggerFactory.getLogger(DocConverterPdf.class);
private static String OS_NAME = System.getProperty("os.name").toLowerCase();
@Autowired
private DocumentConverter converter;
private static final int ENVIRONMENT = 1;// 环境 1windows 2:linux
private String fileString;// (只涉及pdf2swf路径问题)
@@ -24,6 +27,7 @@ public class DocConverterPdf {
private File convertPdfFile;
private File swfFile;
private File docFile;
private String filesType;
String waterPdfPath;
private String convertHost;
@@ -51,6 +55,7 @@ public class DocConverterPdf {
fileName = fileString.substring(0, fileString.lastIndexOf("."));
if(".doc".equals(fileType.toLowerCase()) || ".docx".equals(fileType.toLowerCase()) || ".xlsx".equals(fileType.toLowerCase()) || ".xls".equals(fileType.toLowerCase()) || ".ppt".equals(fileType.toLowerCase()) || ".pptx".equals(fileType.toLowerCase())){
docFile = new File(fileString);
filesType = fileType.toLowerCase();
convertPdfFile=new File(fileName+"_C"+ ".pdf");
pdfFile = new File(fileName + ".pdf");
swfFile = new File(fileName + ".swf");
@@ -60,6 +65,41 @@ public class DocConverterPdf {
}
}
/**
* openOffice目录,window 可能在C://Program Files (x86)//OpenOffice 4
*/
private static final String openOfficeHome = "/opt/openoffice4";
/**
* openOffice端口
*/
private static final int openOfficePort = 8100;
/**
* 转化文档
* @param input
* @param output
*/
public void convertFile(File input , File output) throws OfficeException {
//转换,自动识别转化类型
OfficeManager officeManager = LocalOfficeManager.builder()
.install()
.officeHome(openOfficeHome)
.build();
try {
// Start an office process and connect to the started instance (on port 2002).
officeManager.start();
// Convert
JodConverter
.convert(input)
.to(output)
.execute();
} finally {
// Stop the office process
OfficeUtils.stopQuietly(officeManager);
}
}
/**
* 转为PDF
*
@@ -67,22 +107,16 @@ public class DocConverterPdf {
*/
private void doc2pdf() throws Exception {
if (!pdfFile.exists()) {
OpenOfficeConnection connection = null;
logger.info("转换服务地址接口:"+convertHost);
InputStream in = null;
OutputStream out = null;
try {
if(StringUtils.isNotBlank(convertHost)){
connection = new SocketOpenOfficeConnection(convertHost,8100);
}else{
connection = new SocketOpenOfficeConnection(8100);
}
connection.connect();
DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);
converter.convert(docFile, convertPdfFile);
//addWaterToPdf(pdfFile,userId);
// in = new FileInputStream(docFile);
// out = new FileOutputStream(convertPdfFile);
convertFile(docFile,convertPdfFile);
// converter.convert(in).as(DefaultDocumentFormatRegistry.getFormatByMediaType(filesType)).
// to(out).as(DefaultDocumentFormatRegistry.PDF);
// close the connection
connection.disconnect();
// 开始设置PDF文档相关属性保证其安全性
logger.info("开始设置转换后的PDF文件安全性相关设置");
PDFEditUtils.setPDFFileSecurity(pdfFile.getAbsolutePath(),convertPdfFile.getAbsolutePath());
@@ -91,10 +125,6 @@ public class DocConverterPdf {
logger.error(e.getMessage(),e);
logger.info("****pdf转换器异常,openoffice服务未启动!****");
throw e;
} catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
logger.error(e.getMessage(),e);
logger.info("****pdf转换器异常,读取转换文件失败****");
throw e;
} catch (Exception e) {
logger.error(e.getMessage(),e);
throw e;
@@ -240,11 +270,6 @@ public class DocConverterPdf {
}
public void setConvertHost(String convertHost) {
OS_NAME = OS_NAME.toLowerCase();
if (OS_NAME.contains("win")) {
this.convertHost = convertHost;
} else {
this.convertHost = "62.234.136.153";
}
this.convertHost = convertHost;
}
}
@@ -13,6 +13,9 @@ server.port=9999
#主服务session超时
server.servlet.session.timeout =600
#tomcat /resource/local/version-manager 创建tomcat指定临时目录
server.tomcat.basedir=/resource/local/version-manager
# http-only
server.session.cookie.http-only=true
spring.mvc.async.request-timeout=20000
@@ -64,7 +64,7 @@
<select id="selectLawsId" resultType="string">
select distinct stand_id from sar_laws_attr_detailed_list
select stand_id from sar_laws_attr_detailed_list
LEFT JOIN sar_standards_info si ON sar_laws_attr_detailed_list.stand_id = si.ID
<where>
<if test="standId != null">
@@ -164,7 +164,11 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
saveWordFileName=UUIDUtils.randomUUID20()+"_"+wordFile.getOriginalFilename();
saveWordFilePath=ocrFilePath+saveWordFileName;
logger.info(saveWordFilePath);
FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath));
//生成保存文件
File saveWordFile = new File(saveWordFilePath);
System.out.println(saveWordFile);
wordFile.transferTo(saveWordFile);
// FileUtils.copyInputStreamToFile(wordFile.getInputStream(),new File(saveWordFilePath));
// savePic(wordFile.getInputStream(),saveWordFilePath);
logger.info("word存储完成");
}
@@ -174,7 +178,10 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
saveJsonFileName=UUIDUtils.randomUUID20()+"_"+jsonFile.getOriginalFilename();
saveJsonFilePath=ocrFilePath+saveJsonFileName;
logger.info(saveJsonFilePath);
FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath));
File saveJsonFile = new File(saveJsonFilePath);
System.out.println(saveJsonFile);
wordFile.transferTo(saveJsonFile);
// FileUtils.copyInputStreamToFile(jsonFile.getInputStream(),new File(saveJsonFilePath));
// savePic(jsonFile.getInputStream(),saveJsonFilePath);
logger.info("Json存储完成");
}