JODConverter
--A library that converts the format of Office files using Apache OpenOffice or LibreOffice --Various conversions such as Excel → PDF are possible
The sample code found in the streets has the following flow. However, when the following process is executed, LibreOffice is started and terminated as an external process, so the process takes time. For example, it is not appropriate as a process to be executed for each request of a Web application.
OfficeManager officeManager = LocalOfficeManager.make();
officeManager.start();
//・ ・ ・
//Format conversion (omitted)
//・ ・ ・
officeManager.stop();
The officially recommended method is to start () a single Office Manager when the web app starts, share it with all requests, and stop () when the web app ends. https://github.com/sbraconnier/jodconverter/wiki/Web-Application
ExternalOfficeManager may be effective as it is.
ExternalOfficeManager (JODConverter Local 4.3.0 API) https://www.javadoc.io/static/org.jodconverter/jodconverter-local/4.3.0/org/jodconverter/local/office/ExternalOfficeManager.html
[1] Start LibreOffice with the arguments specified as follows.
soffice.exe -accept="socket,host=127.0.0.1,port=2002;urp;"
[2] When converting the format, use ExternalOfficeManager to connect to the started LibreOffice. This process can be done reasonably fast.
OfficeManager officeManager = ExternalOfficeManager.make();
officeManager.start();
//Omission
officeManager.stop();
However, as described in Javadoc, JOD Converter does not restart LibreOffice even if LibreOffice terminates abnormally.
Since this implementation does not manage the Office process, it does not support auto-restarting the process if it exits unexpectedly.
Recommended Posts