I am planning to use JODConverter
to do my conversion of office files to PDF. From the tutorial I read that the API instance should be started when the web app starts and closed when the web app closes.
The code would be something like
// web app starts
OfficeManager officeManager = new ManagedProcessOfficeManager();
officeManager.start();
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
converter.convert(sourceFile,targetFile);
// web app stops
officeManager.stop();
The question is where do put the lines of code for starting and stopping the instance (XML or Java classes) ?
Based on the information provided by JB Nizet, I got it working with
@Service
public class JODConverter {
OfficeManager officeManager;
public void convertToPDF() {
OfficeDocumentConverter converter = new OfficeDocumentConverter(
officeManager);
converter.convert(new File("test.odt"), new File("test.pdf"));
}
@PostConstruct
public void start() {
officeManager = new DefaultOfficeManagerConfiguration()
.buildOfficeManager();
officeManager.start();
}
@PreDestroy
public void stop() {
officeManager.stop();
}
}