我创建了一个 Java 代码来将 RTF 格式的文档转换为 PDF 格式。程序在 Windows 中正常运行。但它在linux中给出了错误。有人可以告诉我这段代码的问题吗?
Java代码:
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
import java.io.*;
public class Main {
public static void main(String[] args) {
File inputWord = new File("sample.rtf");
File outputFile = new File("sample.pdf");
try {
InputStream docxInputStream = new FileInputStream(inputWord);
OutputStream outputStream = new FileOutputStream(outputFile);
IConverter converter = LocalConverter.builder().build();
converter.convert(docxInputStream).as(DocumentType.RTF).to(outputStream).as(DocumentType.PDF).execute();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
我使用documents4j 1.1.3 版来实现这段代码。
以下错误在linux环境中给出:
ERROR com.documents4j.conversion.msoffice.MicrosoftWordBridge - Unable to run script: /tmp/1595252529799-0/word_start1195732765.vbs
org.zeroturnaround.exec.ProcessInitException: Could not execute [cmd, /S, /C, ""/tmp/1595252529799-0/word_start1195732765.vbs""] in /tmp/1595252529799-0. Error=2, No such file or directory
at org.zeroturnaround.exec.ProcessInitException.newInstance(ProcessInitException.java:80)
at org.zeroturnaround.exec.ProcessExecutor.invokeStart(ProcessExecutor.java:1002)
at org.zeroturnaround.exec.ProcessExecutor.startInternal(ProcessExecutor.java:970)
at org.zeroturnaround.exec.ProcessExecutor.execute(ProcessExecutor.java:906)
at com.documents4j.conversion.AbstractExternalConverter.runNoArgumentScript(AbstractExternalConverter.java:72)
at com.documents4j.conversion.msoffice.AbstractMicrosoftOfficeBridge.runNoArgumentScript(AbstractMicrosoftOfficeBridge.java:51)
at com.documents4j.conversion.msoffice.AbstractMicrosoftOfficeBridge.tryStart(AbstractMicrosoftOfficeBridge.java:34)
at com.documents4j.conversion.msoffice.MicrosoftWordBridge.startUp(MicrosoftWordBridge.java:46)
at com.documents4j.conversion.msoffice.MicrosoftWordBridge.<init>(MicrosoftWordBridge.java:41)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.documents4j.conversion.ExternalConverterDiscovery.make(ExternalConverterDiscovery.java:30)
at com.documents4j.conversion.ExternalConverterDiscovery.makeAll(ExternalConverterDiscovery.java:42)
at com.documents4j.conversion.ExternalConverterDiscovery.loadConfiguration(ExternalConverterDiscovery.java:85)
at com.documents4j.conversion.DefaultConversionManager.<init>(DefaultConversionManager.java:22)
at com.documents4j.job.LocalConverter.makeConversionManager(LocalConverter.java:79)
at com.documents4j.job.LocalConverter.<init>(LocalConverter.java:51)
at com.documents4j.job.LocalConverter$Builder.build(LocalConverter.java:186)
at Main.main(Main.java:13)