I am trying to create a method which converts office documents into PDF. Now I want to use LibreOffice for this. LibreOffice has a docker image from LinuxServer.io which seems well-maintained. The only problem is that I can’t seem to make a connection to it.
I have started the container from https://docs.linuxserver.io/images/docker-libreoffice/ in my local docker environment. The ports are correctly mapped as I can navigate to the GUI in my browser.
Now when I want to use JODConverter to convert a file, I get a 404 message.
Does anyone know how I can reach the API?
Below is my class in which I have implemented JODConverter:
@ApplicationScoped
public class OfficeConverter implements Converter {
private OfficeManager remoteOfficeManager;
final SslConfig sslConfig = new SslConfig();
@Inject
OfficeConverterConfig officeConverterConfig;
@Override
public Uni<List<File>> convert(List<File> files, ConverterConfiguration conversionConfiguration) {
return Uni
.join()
.all(files.stream().map(this::convertToPdf).toList())
.usingConcurrencyOf(officeConverterConfig.concurrency())
.andFailFast()
.onFailure()
.recoverWithUni(exception -> {
Log.error(
conversionConfiguration.id().toString(),
"A problem occurred while executing the office converter.",
exception
);
return Uni.createFrom().failure(new OfficeConversionProblem());
});
}
private Uni<File> convertToPdf(File file) {
return Uni.createFrom().emitter(emitter -> {
try {
String fileName = file.getName();
String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."));
File tmpFile = Files.createTempFile(fileNameWithoutExtension, ".pdf").toFile();
RemoteConverter.make(remoteOfficeManager).convert(file).to(tmpFile).execute();
emitter.complete(tmpFile);
} catch (IOException | OfficeException exception) {
emitter.fail(new OfficeConversionProblem());
}
});
}
public void init(@Observes StartupEvent event) throws OfficeException {
sslConfig.setEnabled(false);
remoteOfficeManager = RemoteOfficeManager
.builder()
.urlConnection(officeConverterConfig.url())
.sslConfig(sslConfig)
.build();
remoteOfficeManager.start();
}
public void destroy(@Observes ShutdownEvent event) throws OfficeException {
remoteOfficeManager.stop();
}
}
And I am using the following configuration:
office:
concurrency: 5
url: http://localhost:55003