Merge remote-tracking branch 'origin/develop_master' into develop_3
This commit is contained in:
+17
-9
@@ -24,32 +24,40 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!-- openOffice 和 jobconverter-->
|
<!-- openOffice 和 jobconverter-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.artofsolving</groupId>
|
<groupId>org.jodconverter</groupId>
|
||||||
<artifactId>jodconverter</artifactId>
|
<artifactId>jodconverter-core</artifactId>
|
||||||
<scope>system</scope>
|
<version>4.2.2</version>
|
||||||
<version>2.2.2</version>
|
</dependency>
|
||||||
<systemPath>${basedir}/src/main/lib/jodconverter-2.2.2.jar</systemPath>
|
<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>
|
</dependency>
|
||||||
<!-- openOffice end-->
|
<!-- openOffice end-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openoffice</groupId>
|
<groupId>org.openoffice</groupId>
|
||||||
<artifactId>juh</artifactId>
|
<artifactId>juh</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>4.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openoffice</groupId>
|
<groupId>org.openoffice</groupId>
|
||||||
<artifactId>jurt</artifactId>
|
<artifactId>jurt</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>4.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openoffice</groupId>
|
<groupId>org.openoffice</groupId>
|
||||||
<artifactId>ridl</artifactId>
|
<artifactId>ridl</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>4.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openoffice</groupId>
|
<groupId>org.openoffice</groupId>
|
||||||
<artifactId>unoil</artifactId>
|
<artifactId>unoil</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>4.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--OFFICE CONVERTER END-->
|
<!--OFFICE CONVERTER END-->
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
package com.adc.da.convert.common;
|
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.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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class DocConverterPdf {
|
public class DocConverterPdf {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DocConverterPdf.class);
|
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;// 环境 1:windows 2:linux
|
private static final int ENVIRONMENT = 1;// 环境 1:windows 2:linux
|
||||||
private String fileString;// (只涉及pdf2swf路径问题)
|
private String fileString;// (只涉及pdf2swf路径问题)
|
||||||
@@ -24,6 +27,7 @@ public class DocConverterPdf {
|
|||||||
private File convertPdfFile;
|
private File convertPdfFile;
|
||||||
private File swfFile;
|
private File swfFile;
|
||||||
private File docFile;
|
private File docFile;
|
||||||
|
private String filesType;
|
||||||
String waterPdfPath;
|
String waterPdfPath;
|
||||||
|
|
||||||
private String convertHost;
|
private String convertHost;
|
||||||
@@ -51,6 +55,7 @@ public class DocConverterPdf {
|
|||||||
fileName = fileString.substring(0, fileString.lastIndexOf("."));
|
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())){
|
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);
|
docFile = new File(fileString);
|
||||||
|
filesType = fileType.toLowerCase();
|
||||||
convertPdfFile=new File(fileName+"_C"+ ".pdf");
|
convertPdfFile=new File(fileName+"_C"+ ".pdf");
|
||||||
pdfFile = new File(fileName + ".pdf");
|
pdfFile = new File(fileName + ".pdf");
|
||||||
swfFile = new File(fileName + ".swf");
|
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
|
* 转为PDF
|
||||||
*
|
*
|
||||||
@@ -67,22 +107,16 @@ public class DocConverterPdf {
|
|||||||
*/
|
*/
|
||||||
private void doc2pdf() throws Exception {
|
private void doc2pdf() throws Exception {
|
||||||
if (!pdfFile.exists()) {
|
if (!pdfFile.exists()) {
|
||||||
OpenOfficeConnection connection = null;
|
|
||||||
logger.info("转换服务地址接口:"+convertHost);
|
logger.info("转换服务地址接口:"+convertHost);
|
||||||
|
InputStream in = null;
|
||||||
|
OutputStream out = null;
|
||||||
try {
|
try {
|
||||||
if(StringUtils.isNotBlank(convertHost)){
|
// in = new FileInputStream(docFile);
|
||||||
connection = new SocketOpenOfficeConnection(convertHost,8100);
|
// out = new FileOutputStream(convertPdfFile);
|
||||||
}else{
|
convertFile(docFile,convertPdfFile);
|
||||||
connection = new SocketOpenOfficeConnection(8100);
|
// converter.convert(in).as(DefaultDocumentFormatRegistry.getFormatByMediaType(filesType)).
|
||||||
}
|
// to(out).as(DefaultDocumentFormatRegistry.PDF);
|
||||||
connection.connect();
|
|
||||||
DocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);
|
|
||||||
converter.convert(docFile, convertPdfFile);
|
|
||||||
|
|
||||||
//addWaterToPdf(pdfFile,userId);
|
|
||||||
|
|
||||||
// close the connection
|
// close the connection
|
||||||
connection.disconnect();
|
|
||||||
// 开始设置PDF文档相关属性保证其安全性
|
// 开始设置PDF文档相关属性保证其安全性
|
||||||
logger.info("开始设置转换后的PDF文件安全性相关设置");
|
logger.info("开始设置转换后的PDF文件安全性相关设置");
|
||||||
PDFEditUtils.setPDFFileSecurity(pdfFile.getAbsolutePath(),convertPdfFile.getAbsolutePath());
|
PDFEditUtils.setPDFFileSecurity(pdfFile.getAbsolutePath(),convertPdfFile.getAbsolutePath());
|
||||||
@@ -91,10 +125,6 @@ public class DocConverterPdf {
|
|||||||
logger.error(e.getMessage(),e);
|
logger.error(e.getMessage(),e);
|
||||||
logger.info("****pdf转换器异常,openoffice服务未启动!****");
|
logger.info("****pdf转换器异常,openoffice服务未启动!****");
|
||||||
throw e;
|
throw e;
|
||||||
} catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
|
|
||||||
logger.error(e.getMessage(),e);
|
|
||||||
logger.info("****pdf转换器异常,读取转换文件失败****");
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage(),e);
|
logger.error(e.getMessage(),e);
|
||||||
throw e;
|
throw e;
|
||||||
@@ -240,11 +270,6 @@ public class DocConverterPdf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setConvertHost(String convertHost) {
|
public void setConvertHost(String convertHost) {
|
||||||
OS_NAME = OS_NAME.toLowerCase();
|
this.convertHost = convertHost;
|
||||||
if (OS_NAME.contains("win")) {
|
|
||||||
this.convertHost = convertHost;
|
|
||||||
} else {
|
|
||||||
this.convertHost = "62.234.136.153";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ server.port=9999
|
|||||||
#主服务session超时
|
#主服务session超时
|
||||||
server.servlet.session.timeout =600
|
server.servlet.session.timeout =600
|
||||||
|
|
||||||
|
#tomcat /resource/local/version-manager 创建tomcat指定临时目录
|
||||||
|
server.tomcat.basedir=/resource/local/version-manager
|
||||||
|
|
||||||
# http-only
|
# http-only
|
||||||
server.session.cookie.http-only=true
|
server.session.cookie.http-only=true
|
||||||
spring.mvc.async.request-timeout=20000
|
spring.mvc.async.request-timeout=20000
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<select id="selectLawsId" resultType="string">
|
<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
|
LEFT JOIN sar_standards_info si ON sar_laws_attr_detailed_list.stand_id = si.ID
|
||||||
<where>
|
<where>
|
||||||
<if test="standId != null">
|
<if test="standId != null">
|
||||||
|
|||||||
@@ -164,7 +164,11 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
saveWordFileName=UUIDUtils.randomUUID20()+"_"+wordFile.getOriginalFilename();
|
saveWordFileName=UUIDUtils.randomUUID20()+"_"+wordFile.getOriginalFilename();
|
||||||
saveWordFilePath=ocrFilePath+saveWordFileName;
|
saveWordFilePath=ocrFilePath+saveWordFileName;
|
||||||
logger.info(saveWordFilePath);
|
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);
|
// savePic(wordFile.getInputStream(),saveWordFilePath);
|
||||||
logger.info("word存储完成");
|
logger.info("word存储完成");
|
||||||
}
|
}
|
||||||
@@ -174,7 +178,10 @@ public class OCRRestfulServiceImpl implements OCRRestfulService {
|
|||||||
saveJsonFileName=UUIDUtils.randomUUID20()+"_"+jsonFile.getOriginalFilename();
|
saveJsonFileName=UUIDUtils.randomUUID20()+"_"+jsonFile.getOriginalFilename();
|
||||||
saveJsonFilePath=ocrFilePath+saveJsonFileName;
|
saveJsonFilePath=ocrFilePath+saveJsonFileName;
|
||||||
logger.info(saveJsonFilePath);
|
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);
|
// savePic(jsonFile.getInputStream(),saveJsonFilePath);
|
||||||
logger.info("Json存储完成");
|
logger.info("Json存储完成");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user