org.artofsolving.jodconverter.office.OfficeManager is not initializing in wicket

1.5k views Asked by At

I have upgraded my application from Wicket 1.x to 8.x version.

I am facing an issue to convert Excel file into PDF format.

Using this below dependencies:

<dependency>
    <groupId>net.sf.jodconverter</groupId>
    <artifactId>jodconverter</artifactId>
    <version>3.0-beta-4</version>
</dependency>

Using these import classes

import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeConnectionProtocol;
import org.artofsolving.jodconverter.office.OfficeManager;

Getting this below error on this line while calling buildOfficeManager() method.

OfficeManager officeManager = eomc.buildOfficeManager();

I am getting this below exception on this above line:

java.lang.ClassNotFoundException: com.sun.star.connection.NoConnectException at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180) at org.artofsolving.jodconverter.office.ExternalOfficeManager.(ExternalOfficeManager.java:55) at org.artofsolving.jodconverter.office.ExternalOfficeManagerConfiguration.buildOfficeManager(ExternalOfficeManagerConfiguration.java:50)

Using below system parameters:

[openofficeHome=C:/Program Files/openoffice.org3, hostname=127.0.0.1, port=8100, protocol=SOCKET]

Below is the more detail of code:

ExternalOfficeManagerConfiguration eomcTest = new ExternalOfficeManagerConfiguration();
eomcTest.setConnectOnStart(true);

eomcTest.setConnectionProtocol(ooConfig.getProtocol());

if (OfficeConnectionProtocol.PIPE.equals(ooConfig.getProtocol())) {
    eomcTest.setPipeName("officePipe");
} else {
    eomcTest.setPortNumber(ooConfig.getPort());
}

OfficeManager officeManager = eomcTest.buildOfficeManager();
officeManager.start();
OfficeDocumentConverter officeDocConverter = new OfficeDocumentConverter(officeManager);
resultFile = File.createTempFile(sheetName, TypeOfFile.PDF.getFileExtension());
officeDocConverter.convert(tempFile, resultFile);
fout.close();
officeManager.stop();

Kindly anyone let me know why buildOfficeManager() is giving error here and what can be the solution here to resolve this issue. It will be more appreciable.

2

There are 2 answers

3
martin-g On BEST ANSWER

According to https://search.maven.org/search?q=fc:com.sun.star.connection.NoConnectException you need to add org.libreoffice:libreoffice (or the old org.libreoffice:ridl) dependency to Maven's pom.xml.

I don't see net.sf.jodconverter at https://search.maven.org/search?q=jodconverter. You may try with a more recent version of it - probably any of the listed ones here: https://search.maven.org/search?q=g:org.jodconverter

0
user3552342 On

I have resolved this issue and above code is working fine to convert excel file into pdf file with jodconverter API.

In my case, excel file and pdf file both were having the same name which was causing the issue to return the same excel file on pdf download link. After a change in pdf's name, it resolved my issue.