feat: There is no way the convert 4.3
This commit is contained in:
@@ -23,20 +23,26 @@
|
|||||||
<version>3.0.0</version>
|
<version>3.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- openOffice 和 jobconverter-->
|
<!-- openOffice 和 jobconverter-->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.artofsolving</groupId>
|
||||||
|
<artifactId>jodconverter</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jodconverter</groupId>
|
<groupId>org.jodconverter</groupId>
|
||||||
<artifactId>jodconverter-core</artifactId>
|
<artifactId>jodconverter-core</artifactId>
|
||||||
<version>4.2.2</version>
|
<version>4.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jodconverter</groupId>
|
<groupId>org.jodconverter</groupId>
|
||||||
<artifactId>jodconverter-spring-boot-starter</artifactId>
|
<artifactId>jodconverter-spring-boot-starter</artifactId>
|
||||||
<version>4.2.2</version>
|
<version>4.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jodconverter</groupId>
|
<groupId>org.jodconverter</groupId>
|
||||||
<artifactId>jodconverter-local</artifactId>
|
<artifactId>jodconverter-local</artifactId>
|
||||||
<version>4.2.2</version>
|
<version>4.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- openOffice end-->
|
<!-- openOffice end-->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
package com.adc.da.convert.common;
|
package com.adc.da.convert.common;
|
||||||
|
|
||||||
|
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
|
||||||
|
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.core.DocumentConverter;
|
||||||
import org.jodconverter.JodConverter;
|
import org.jodconverter.core.office.OfficeException;
|
||||||
import org.jodconverter.OfficeDocumentConverter;
|
import org.jodconverter.core.office.OfficeManager;
|
||||||
import org.jodconverter.document.DefaultDocumentFormatRegistry;
|
import org.jodconverter.core.office.OfficeUtils;
|
||||||
import org.jodconverter.office.*;
|
import org.jodconverter.local.JodConverter;
|
||||||
|
import org.jodconverter.local.office.LocalOfficeManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.ConnectException;
|
||||||
|
|
||||||
public class DocConverterPdf {
|
public class DocConverterPdf {
|
||||||
|
|
||||||
@@ -75,6 +79,35 @@ public class DocConverterPdf {
|
|||||||
*/
|
*/
|
||||||
private static final int openOfficePort = 8100;
|
private static final int openOfficePort = 8100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param input 初始文件的路径,例:C:\Users\...\Desktop\test\1.doc
|
||||||
|
* @param output 转换后的存储路径,例:C:\Users\...\Desktop\test\
|
||||||
|
*/
|
||||||
|
public void convert(File input , File output){
|
||||||
|
|
||||||
|
if (!input.exists()){
|
||||||
|
System.out.println("源文件不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection("0.0.0.0", 8100);
|
||||||
|
// SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection("10.10.66.176", 8100);
|
||||||
|
try {
|
||||||
|
connection.connect();
|
||||||
|
System.out.println("获取连接成功!");
|
||||||
|
} catch (ConnectException e) {
|
||||||
|
System.out.println("获取连接失败!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// OpenOfficeDocumentConverter converter = new OpenOfficeDocumentConverter(connection);
|
||||||
|
StreamOpenOfficeDocumentConverter converter = new StreamOpenOfficeDocumentConverter(connection);
|
||||||
|
System.out.println("开始转换!");
|
||||||
|
converter.convert(input, output);
|
||||||
|
System.out.println("转换成功!");
|
||||||
|
System.out.println("关闭连接!");
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转化文档
|
* 转化文档
|
||||||
* @param input
|
* @param input
|
||||||
@@ -113,7 +146,7 @@ public class DocConverterPdf {
|
|||||||
try {
|
try {
|
||||||
// in = new FileInputStream(docFile);
|
// in = new FileInputStream(docFile);
|
||||||
// out = new FileOutputStream(convertPdfFile);
|
// out = new FileOutputStream(convertPdfFile);
|
||||||
convertFile(docFile,convertPdfFile);
|
convert(docFile,convertPdfFile);
|
||||||
// converter.convert(in).as(DefaultDocumentFormatRegistry.getFormatByMediaType(filesType)).
|
// converter.convert(in).as(DefaultDocumentFormatRegistry.getFormatByMediaType(filesType)).
|
||||||
// to(out).as(DefaultDocumentFormatRegistry.PDF);
|
// to(out).as(DefaultDocumentFormatRegistry.PDF);
|
||||||
// close the connection
|
// close the connection
|
||||||
|
|||||||
Reference in New Issue
Block a user