Java JOD转换器未正确设置
我正在尝试JODConverter将docx文件转换为pdf。我使用的是LibreOffice 5.3.4。我试着运行这段代码,但我得到了一个错误,请看这个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
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未设置且无法自动检测
如何设置请详细解释