天天看點

JodConverter Error :officeHome not set and could not be auto-detected 原問題:解答:

JodConverter Error :officeHome not set and could not be auto-detected 原問題:解答:

 原問題:

I am trying to set up jodconverter using libre office. when i try to use it i get this error: officeHome not set and could not be auto-detected.

I set office home but this is still coming up. Below is how I have it set up. Can anyone advise what I am doing wrong here.

public void convert(){
    File inputFile = new File("SippKey.rtf");
    File outputFile = new File("SippKeyCon.html");
    
    LocalOfficeManager.builder().officeHome("/opt/libreoffice6.0").build();
    final LocalOfficeManager officeManager = LocalOfficeManager.install();

    try {
    // Start an office process and connect to the started instance (on port 2002).
    officeManager.start();
    // Convert
    JodConverter
             .convert(inputFile)
             .to(outputFile)
             .execute();
    } catch (OfficeException ex) {
        //  ex.printStackTrace();
        Logger.getLogger(QrGUI.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        // Stop the office process
        OfficeUtils.stopQuietly(officeManager);
    }
}
           

解答:

You should initialize the manager this way:

final LocalOfficeManager officeManager = 
    LocalOfficeManager.builder().officeHome("/opt/libreoffice6.0").install().build();
           

LocalOfficeManager.install() will just create a default manager which will try to autodetect the office installation. So the manager you are actually using is not the one you initialized with the custom office home directory. 

注意:需要先安裝 openOffice 環境。否則無法注入相應的 Bean,如 localOfficeManager 等。

JodConverter Error :officeHome not set and could not be auto-detected 原問題:解答:

原連結:https://stackoverflow.com/questions/50474587/jodconverter-error-officehome-not-set-and-could-not-be-auto-detected

上一篇: 我工作了

繼續閱讀