1

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) ?

abiieez
  • 3,139
  • 14
  • 57
  • 110
  • 1
    http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/beans.html#beans-factory-nature – JB Nizet Oct 14 '14 at 06:15
  • I've configured my service to implements `org.springframework.context.Lifecycle`. Thanks! – abiieez Oct 14 '14 at 06:20
  • As the doc says, the best, modern, recommended way is ti use PreDestroy and PostConstruct annotated methods. – JB Nizet Oct 14 '14 at 06:21

1 Answers1

3

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

}
abiieez
  • 3,139
  • 14
  • 57
  • 110