(解决) 我想将docx文档转换为pdf。由于xdocreport的结果并不十分令人满意,我试用了documents4j。不幸的是,我收到了以下IllegalStateException:
java.lang.IllegalStateException: class com.documents4j.conversion.msoffice.MicrosoftWordBridge could not be created by a (File, long, TimeUnit) constructor
at com.documents4j.conversion.ExternalConverterDiscovery.make(ExternalConverterDiscovery.java:32)
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 me.jonasbecker.excelaccountingtablemanager.core.dunning.ConfirmDunningWorkbookBuilder.getAttachment(ConfirmDunningWorkbookBuilder.java:469)
at me.jonasbecker.excelaccountingtablemanager.core.dunning.ConfirmDunningWorkbookBuilder.build(ConfirmDunningWorkbookBuilder.java:241)
at me.jonasbecker.excelaccountingtablemanager.ui.ConfirmDunningUi$1.run(ConfirmDunningUi.java:229)
Caused by: java.lang.reflect.InvocationTargetException
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)
... 9 more
Caused by: com.documents4j.throwables.ConverterAccessException: Unable to run script: \word_start199932774.vbs
at com.documents4j.conversion.AbstractExternalConverter.runNoArgumentScript(AbstractExternalConverter.java:76)
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:44)
at com.documents4j.conversion.msoffice.MicrosoftWordBridge.<init>(MicrosoftWordBridge.java:39)
... 14 more
Caused by: java.io.IOException: Could not execute [cmd, /S, /C, ""F:\word_start199932774.vbs""] in .
at org.zeroturnaround.exec.ProcessExecutor.invokeStart(ProcessExecutor.java:936)
at org.zeroturnaround.exec.ProcessExecutor.startInternal(ProcessExecutor.java:910)
at org.zeroturnaround.exec.ProcessExecutor.execute(ProcessExecutor.java:860)
at com.documents4j.conversion.AbstractExternalConverter.runNoArgumentScript(AbstractExternalConverter.java:72)
... 18 more
Caused by: java.io.IOException: Cannot run program "cmd" (in directory ""): CreateProcess error=123, Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at org.zeroturnaround.exec.ProcessExecutor.invokeStart(ProcessExecutor.java:931)
... 21 more
Caused by: java.io.IOException: CreateProcess error=123, Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
at java.lang.ProcessImpl.start(ProcessImpl.java:137)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 22 more
我的第一个猜测是它在路径周围放了一对额外的引号(cmd,/ S,/ C,&#34;&#34; F:\ word_start199932774.vbs&#34;&#34; )。有什么我可以做的或者还有别的我做错了吗?
欢迎任何帮助,非常感谢。
更新:
我发现了我的错误,而不是这一行:
IConverter converter = LocalConverter.builder().baseFolder(new File("")).workerPool(20, 25, 1, TimeUnit.SECONDS).processTimeout(5, TimeUnit.SECONDS).build();
我需要使用这一行:
IConverter converter = LocalConverter.builder().baseFolder(base).workerPool(20, 25, 1, TimeUnit.SECONDS).processTimeout(5, TimeUnit.SECONDS).build();
base是一个临时目录。我的坏。