我试图让 JODConverter 在带有 Jdk 1.8.0_144 的 Window 10 上工作。正如您从代码中看到的那样,我认为这可能是时间问题,因此会出现延迟。如您所见,JODConverter 认为 OfficeManager 正在运行。我正在使用以下代码:
import java.io.File;
import org.jodconverter.JodConverter;
import org.jodconverter.office.LocalOfficeManager;
import org.jodconverter.office.OfficeException;
import org.jodconverter.office.OfficeManager;
import org.jodconverter.office.OfficeUtils;
import org.jodconverter.process.ProcessManager;
public class JodConverterTest {
public static void main(String[] args) throws OfficeException, InterruptedException {
OfficeManager officeManager
= LocalOfficeManager.builder()
.officeHome("C:\\Program Files\\LibreOffice")
.portNumbers(2372)
.build();
officeManager.start();
File inputFile = new File("c:\\test\\rtf.rtf");
File outputFile = new File("c:\\test\\rtf.pdf");
try {
System.out.println("officeManager.isRunning()="+officeManager.isRunning());
Thread.sleep(10000);
System.out.println("officeManager.isRunning()="+officeManager.isRunning());
JodConverter.convert(inputFile).to(outputFile).execute();
} finally {
// Stop the office process
OfficeUtils.stopQuietly(officeManager);
}
}
}
运行时出现以下错误:-
officeManager.isRunning()=true
officeManager.isRunning()=true
Exception in thread "main" java.lang.IllegalStateException: An office manager is required in order to build a converter.
at org.jodconverter.job.AbstractConverter.<init>(AbstractConverter.java:57)
at org.jodconverter.LocalConverter.<init>(LocalConverter.java:93)
at org.jodconverter.LocalConverter.<init>(LocalConverter.java:49)
at org.jodconverter.LocalConverter$Builder.build(LocalConverter.java:202)
at org.jodconverter.LocalConverter.make(LocalConverter.java:73)
at org.jodconverter.JodConverter.convert(JodConverter.java:48)
at ZPlaying.JodConverterTest.main(JodConverterTest.java:30)
------------------------------------------------------------------------
BUILD FAILURE
我尝试过的事情:- - 更改端口号 - 研究是否可以找到 java Process Manager 的类路径并添加以下内容,但我找不到 ProcessManager 的类路径,因为我不太了解关于这一点:- .processManager("com.example.foo.CustomProcessManager") - 还想知道这是否与通过 Netbeans 运行有关?
这是适用的 Maven 依赖项:-
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local</artifactId>
<version>4.1.1</version>
</dependency>
我已经在 C:\Program Files\LibreOffice 中安装了 Libre(全新安装)