【问题标题】:JOD Converter not setting up properlyJOD 转换器未正确设置
【发布时间】:2017-08-07 10:49:53
【问题描述】:

我正在尝试使用 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)

【问题讨论】:

  • 消息很清楚:officeHome not set and could not be auto-detected
  • 如何设置请详细说明

标签: java libreoffice jodconverter


【解决方案1】:

JODConverter 只会检测默认的 office 安装(在 Windows 上:c:// 程序文件...)。尝试将自己设置为 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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    相关资源
    最近更新 更多