Install Libreoffice (JodConverter) with dockerfile

cancel
Showing results for 
Search instead for 
Did you mean: 
anakin98000
Active Member

Install Libreoffice (JodConverter) with dockerfile

Hi,

I use alfresco-content-repository-community:7.3.1 (docker)

I need to use jodconverter in java process. So I updated my Dockerfile as follow, in order to install LibreOffice :

#Installing LibreOffice
COPY backend/LibreOffice_6.3.5.2_Linux_x86-64_rpm /usr/local/LibreOffice_6.3.5.2_Linux_x86-64_rpm
RUN cd /usr/local/LibreOffice_6.3.5.2_Linux_x86-64_rpm/RPMS/
RUN yum -y install /usr/local/LibreOffice_6.3.5.2_Linux_x86-64_rpm/RPMS/*.rpm;

 

I find libreoffice6.3 in /opt folder inside container. However "libreoffice -_version" says : 

bash: libreoffice: command not found

 

When the java process is executed i get the following error: ServiceManager' started but its pid could not be found :

OfficeProcessManager          : Submitting task 'Start' and waiting...
2023-08-03 13:51:37.133  INFO 1 --- [ProcessThread-0] 
org.jodconverter.office.OfficeProcess    : Starting process with acceptString 
'socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ServiceManager' and 
profileDir '/usr/local/tomcat/temp/.jodconverter_socket_host-127.0.0.1_port- 
2002_tcpNoDelay-1'
2023-08-03 13:51:37.148  INFO 1 --- [ProcessThread-0] 
org.jodconverter.office.OfficeProcess    : Started process; pid = -2
2023-08-03 13:51:37.149 ERROR 1 --- [TaskScheduler16] 
c.m.service.TransformationService     : ERROR convertToDocx: 
org.jodconverter.office.OfficeException: A process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ServiceManager' started but its pid could not be found
    at org.jodconverter.office.OfficeProcess.start(OfficeProcess.java:354)
    at org.jodconverter.office.OfficeProcessManager.doStartProcessAndConnect(OfficeProcessManager.java:100)
    at org.jodconverter.office.OfficeProcessManager.access$100(OfficeProcessManager.java:40)
    at org.jodconverter.office.OfficeProcessManager$4.call(OfficeProcessManager.java:260)
    at org.jodconverter.office.OfficeProcessManager$4.call(OfficeProcessManager.java:255)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

2023-08-03 13:51:37.150  INFO 1 --- [TaskScheduler16] 
 o.j.office.AbstractOfficeManagerPool     : Stopping the office manager pool...
2023-08-03 13:51:37.152  INFO 1 --- [TaskScheduler16] o.j.office.OfficeProcessManager          
: Submitting task 'Stop' and waiting...
2023-08-03 13:51:37.159  INFO 1 --- [ProcessThread-0] 
org.jodconverter.office.OfficeProcess    : Trying to forcibly terminate process: 
'host=127.0.0.1,port=2002,tcpNoDelay=1'; pid: -2
2023-08-03 13:51:37.166  INFO 1 --- [ProcessThread-0] o.j.office.OfficeProcessManager          
: process forcibly terminated with code 127
2023-08-03 13:51:37.166  INFO 1 --- [ProcessThread-0] o.j.office.OfficeProcessManager          
: process exited with code 127
2023-08-03 13:51:37.174  INFO 1 --- [TaskScheduler16] o.j.office.AbstractOfficeManagerPool     : Office manager stopped

 

This is my java code :

libreOfficeHome = libreoff.getValue();
        
        File initialFile = new File(workPath + "/" + fileName);
        LocalOfficeManager localOfficeManager = LocalOfficeManager.builder()
                .install()
                .officeHome(libreOfficeHome) //your path to openoffice
                .build();

        try {
            localOfficeManager.start();
            final DocumentFormat format = DocumentFormat.builder()
                    .from(DefaultDocumentFormatRegistry.DOCX)
                    .build();

            LocalConverter
                  .make()
                  .convert(new FileInputStream(initialFile))
                  .as(DefaultDocumentFormatRegistry.getFormatByMediaType("application/msword"))
                  .to(new File(targetFile))
                  .as(format)
                  .execute();

        } catch (Exception e) {
            logger.error("ERROR convertToDocx: " + ExceptionUtils.getStackTrace(e));
            return null;
        } finally {
            OfficeUtils.stopQuietly(localOfficeManager);
        }

Same error with libreoffice 7.5

How can I solve that ? Thx

1 Reply
abhinavmishra14
Advanced

Re: Install Libreoffice (JodConverter) with dockerfile

I think -version is not an option available. Try --help

Probably docker container is not able to execute the command to find the process id. Once your container is up try to manually access 'ps' command and see if it is still working. Also try to see if you can manually kill any process using "kill" command.

You may have to install procpshttps://yum-info.contradodigital.com/view-package/installed/procps/ 

look for appropriate command to install based on the your linux version. ACS 7.3 is based on rockylinux. 

You can find some help here : https://stackoverflow.com/questions/26982274/ps-command-doesnt-work-in-docker-container

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)