Skip to content

Instantly share code, notes, and snippets.

@ulugbekrozimboyev
Created July 4, 2018 15:44
Show Gist options
  • Save ulugbekrozimboyev/2a4daf46d1146b5910315eb81071c908 to your computer and use it in GitHub Desktop.
Save ulugbekrozimboyev/2a4daf46d1146b5910315eb81071c908 to your computer and use it in GitHub Desktop.
public class JODConverter {
private static volatile OfficeManager officeManager;
private static volatile OfficeDocumentConverter converter;
public static void startOfficeManager(){
try {
officeManager = new DefaultOfficeManagerConfiguration()
.setOfficeHome(new File('libre office home path'))
.setPortNumbers(8100, 8101, 8102, 8103, 8104 )
.setTaskExecutionTimeout(600000L) // for big files
.setTaskQueueTimeout(200000L) // wait if all port were busy
.buildOfficeManager();
officeManager.start();
// 2) Create JODConverter converter
converter = new OfficeDocumentConverter(officeManager);
} catch (Throwable e){
e.printStackTrace();
}
}
public static void convertPDF(File inputFile, File outputFile) throws Throwable {
converter.convert(inputFile, outputFile);
}
public static void stopOfficeManager(){
officeManager.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment