2

I am trying JODConverter to convert docx file to pdf. I am using LibreOffice 5.3.4. I tried running this code but i am getting an error see this.

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)

1 Answers1

3

JODConverter will only detect default office installation (on Windows: c:// program files...). Try to set yourself the home directory of LibreOffice.

You can use DefaultOfficeManagerConfiguration#setOfficeHome to do so:

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();
}
sbraconnier
  • 465
  • 5
  • 11