Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JOD转换器未正确设置_Java_Libreoffice_Jodconverter - Fatal编程技术网

Java JOD转换器未正确设置

Java JOD转换器未正确设置,java,libreoffice,jodconverter,Java,Libreoffice,Jodconverter,我正在尝试JODConverter将docx文件转换为pdf。我使用的是LibreOffice 5.3.4。我试着运行这段代码,但我得到了一个错误,请看这个 import org.artofsolving.jodconverter.OfficeDocumentConverter; import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; import org.artofsolving.jodcon

我正在尝试JODConverter将docx文件转换为pdf。我使用的是LibreOffice 5.3.4。我试着运行这段代码,但我得到了一个错误,请看这个

import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;

import java.io.File;

public class PDF    {

    public static void main(String[] args) {
    OfficeManager manager = new DefaultOfficeManagerConfiguration().buildOfficeManager();
    manager.start();
    OfficeDocumentConverter converter = new OfficeDocumentConverter(manager);
    converter.convert(new File("E:/Project Synopsis.docx"), new File("E:/Project Synopsis.pdf"));
    }
}

Exception in thread "main" java.lang.IllegalStateException: officeHome not set and could not be auto-detected
at org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration.buildOfficeManager(DefaultOfficeManagerConfiguration.java:163)
at com.company.PDF.main(PDF.java:12)

JODConverter将仅检测默认的office安装(在Windows:c://程序文件…)。尝试将自己设置为LibreOffice的主目录

您可以使用DefaultOfficeManager配置#setOfficeHome执行以下操作:

DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration();
config.setOfficeHome(new File("Path to Office"));
OfficeManager manager = config.buildOfficeManager();
try {
    manager.start();
    OfficeDocumentConverter converter = new OfficeDocumentConverter(manager);
    converter.convert(new File("E:/Project Synopsis.docx"), new File("E:/Project Synopsis.pdf"));
} finally {
    manager.stop();
}

信息很清楚:
officeHome未设置且无法自动检测
如何设置请详细解释