gpt4 book ai didi

java - JODConverter 告诉我需要办公室经理才能构建转换器

转载 作者:行者123 更新时间:2023-12-03 11:20:35 33 4
gpt4 key购买 nike

我正在尝试让 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(全新安装)

最佳答案

得到它的工作。这是一个解决方案:-

package ZPlaying;

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;

public class JodConverterTest {

public static void main(String[] args) throws OfficeException, InterruptedException {
OfficeManager officeManager = LocalOfficeManager.builder()
.install()
.officeHome("C:\\Program Files\\LibreOffice")
.build();
File inputFile = new File("c:\\test\\rtf.rtf");
File outputFile = new File("c:\\test\\rtf.pdf");
try {
// Start an office process and connect to the started instance (on port 2002).
officeManager.start();
// Convert
JodConverter
.convert(inputFile)
.to(outputFile)
.execute();
} finally {
// Stop the office process
OfficeUtils.stopQuietly(officeManager);
}
}

关于java - JODConverter 告诉我需要办公室经理才能构建转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52460055/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com