我正在使用 JODConverter 连接到 OpenOffice 4 并将 rtf 文档转换为 pdf。
除了一个奇怪的问题外,它工作得很好,当我第一次尝试转换时,我得到一个连接被拒绝的异常;它从第二次开始工作。
计算机启动后,我在每次第一次转换时都会收到异常。
这是我的测试课
import java.io.File;
import java.io.IOException;
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;
public class ConverterServiceTest
{
public static void main(String[] args) throws IOException
{
File inputFile = new File("C:/Prova/Esempi/TestSign.rtf");
File outputFile = new File("C:/Prova/Esempi/TestSign.pdf");
int openOfficePort = 8100;
System.out.println("Provo a lanciare il processo di OpenOffice");
String command = "\"C:/Program Files (x86)/OpenOffice 4/program/soffice.exe\"" +
"-headless -accept=\"socket,host=localhost,port="
+ openOfficePort + ";urp;\" -nofirststartwizard";
System.out.println("Comando = " + command);
Process p = Runtime.getRuntime().exec(command);
System.out.println("OpenOffice lanciato, provo la connessione alla porta "
+ openOfficePort);
OpenOfficeConnection connection =
new SocketOpenOfficeConnection(openOfficePort);
connection.connect();
System.out.println("Connessione aperta! Provo la conversione");
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
System.out.println("Conversione effettuata");
connection.disconnect();
p.destroy();
System.out.println("Connessione chiusa e processo killato");
}
}
这是例外:
Exception in thread "main" java.net.ConnectException: connection failed: socket,host=localhost,port=8100,tcpNoDelay=1: java.net.ConnectException: Connection refused: connect
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:79)
at test.converter.ConverterServiceTest.main(ConverterServiceTest.java:29)
有谁知道为什么会这样?我该如何解决这个奇怪的问题?
谢谢你的建议,对不起我的英语不完美。