原问题:
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 等。