Search code examples
javalibreoffice

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);
   }
    }

Solution

  • 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.