OpenOffice使用JAVA将doc转换为pdf

刺猬

我知道它有很多问题。但是我已经读了很多,但仍然无法正常工作。我已经将OpenOffice安装到我的comp上:https : //www.openoffice.org/download/index.html

我也尝试过此解决方案,但不起作用:连接到OpenOffice .org时连接失败

如果我想运行我的代码,则会出现以下错误:

    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 TestCon.main(TestCon.java:24

)

我如何管理连接到我的openoffice程序。PS:我想在Windows 7 64x上使用它

我用这个简单的代码

import java.io.File;
import java.net.ConnectException;

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 TestCon {

    /**
     * @param args
     * @throws ConnectException 
     */
    public static void main(String[] args) throws ConnectException {
        // TODO Auto-generated method stub
        File inputFile = new File("Resume.doc");
        File outputFile = new File("document.pdf");

        // connect to an OpenOffice.org instance running on port 8100
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
        connection.connect();

        // convert
        DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
        converter.convert(inputFile, outputFile);

        // close the connection
        connection.disconnect();
    }
}
詹斯

您必须启动openoffice服务:

 soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

然后,您可以连接到该服务并转换您的文档。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章