JOD Converter未正确设置

问题描述:

我正在尝试JODConverter将docx文件转换为pdf。我正在使用LibreOffice 5.3.4。我试着运行这段代码,但是我看到这个错误。JOD Converter未正确设置

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) 
+0

的信息是明确的:'officeHome没有设置,无法进行自动detected' – Jens

+0

如何设置PLZ详细讲解 – CodingGeek

JODConverter只会检测默认的办公室安装(在Windows上:c:// program files ...)。尝试将自己设置为LibreOffice的主目录。

您可以使用DefaultOfficeManagerConfiguration#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(); 
}