feat: There is no way the convert 4.3
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
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.jodconverter.DocumentConverter;
|
||||
import org.jodconverter.JodConverter;
|
||||
import org.jodconverter.OfficeDocumentConverter;
|
||||
import org.jodconverter.document.DefaultDocumentFormatRegistry;
|
||||
import org.jodconverter.office.*;
|
||||
import org.jodconverter.core.DocumentConverter;
|
||||
import org.jodconverter.core.office.OfficeException;
|
||||
import org.jodconverter.core.office.OfficeManager;
|
||||
import org.jodconverter.core.office.OfficeUtils;
|
||||
import org.jodconverter.local.JodConverter;
|
||||
import org.jodconverter.local.office.LocalOfficeManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
|
||||
public class DocConverterPdf {
|
||||
|
||||
@@ -75,6 +79,35 @@ public class DocConverterPdf {
|
||||
*/
|
||||
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
|
||||
@@ -113,7 +146,7 @@ public class DocConverterPdf {
|
||||
try {
|
||||
// in = new FileInputStream(docFile);
|
||||
// out = new FileOutputStream(convertPdfFile);
|
||||
convertFile(docFile,convertPdfFile);
|
||||
convert(docFile,convertPdfFile);
|
||||
// converter.convert(in).as(DefaultDocumentFormatRegistry.getFormatByMediaType(filesType)).
|
||||
// to(out).as(DefaultDocumentFormatRegistry.PDF);
|
||||
// close the connection
|
||||
|
||||
Reference in New Issue
Block a user