我已经使用documents4j将.docx文件转换为.pdf,但是即使日志显示转换成功,pdf也没有显示。
26-Jun-2020 21:45:38.163 INFO [http-nio-80-exec-423] com.documents4j.conversion.msoffice.MicrosoftWordBridge.startUp From-Microsoft-Word-Converter was started successfully
26-Jun-2020 21:45:38.163 INFO [http-nio-80-exec-423] com.documents4j.job.LocalConverter.<init> The documents4j local converter has started successfully
26-Jun-2020 21:45:38.187 INFO [pool-50-thread-1] com.documents4j.conversion.msoffice.AbstractMicrosoftOfficeBridge.doStartConversion Requested conversion from C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\stock\batimp\RECTO_BAT20200045.docx (application/vnd.openxmlformats-officedocument.wordprocessingml.document) to C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\stock\batimp\RECTO_BAT20200045.pdf (application/pdf)
26-Jun-2020 21:45:38.440 INFO [http-nio-80-exec-423] com.documents4j.conversion.msoffice.MicrosoftWordBridge.shutDown From-Microsoft-Word-Converter was shut down successfully
26-Jun-2020 21:45:38.440 INFO [http-nio-80-exec-423] com.documents4j.job.LocalConverter.shutDown The documents4j local converter has shut down successfully
调试还显示以下内容:
LocalConversion{pending=false, cancelled=false, done=true, priority=Priority{value=500, creationTime=1593207938174}, file-system-target=C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps\stock\batimp\RECTO_BAT20200045.pdf}
为什么pdf没有显示在目录中?
程序片段
File wordFile = new File(FILE_NAMEX), target = new File(outputFile1);
IConverter converter = LocalConverter.builder().baseFolder(new File(path+"batimp"))
.workerPool(20, 25, 2, TimeUnit.SECONDS)
.processTimeout(5, TimeUnit.SECONDS).build();
Future<Boolean> conversion = converter.convert(wordFile).as(DocumentType.DOCX).to(target).as(DocumentType.PDF)
.schedule();
converter.shutDown();
添加conversion.get() 会引发以下错误
> 29-Jun-2020 08:52:21.475 INFO [http-nio-80-exec-1]
> com.documents4j.conversion.msoffice.MicrosoftWordBridge.startUp
> From-Microsoft-Word-Converter was started successfully 29-Jun-2020
> 08:52:21.475 INFO [http-nio-80-exec-1]
> com.documents4j.job.LocalConverter.<init> The documents4j local
> converter has started successfully 29-Jun-2020 08:52:21.511 INFO
> [pool-1-thread-1]
> com.documents4j.conversion.msoffice.AbstractMicrosoftOfficeBridge.doStartConversion
> Requested conversion from C:\Program Files\Apache Software
> Foundation\Tomcat
> 9.0\webapps\stock\batimp\FICHE_TECHNIQUE_BAT20200045.docx (application/vnd.openxmlformats-officedocument.wordprocessingml.document)
> to C:\Program Files\Apache Software Foundation\Tomcat
> 9.0\webapps\stock\batimp\FICHE_TECHNIQUE_BAT20200045.pdf (application/pdf) java.util.concurrent.ExecutionException: Could not
> complete conversion
> at com.documents4j.job.FailedConversionFuture.get(FailedConversionFuture.java:35)
> at com.documents4j.job.FailedConversionFuture.get(FailedConversionFuture.java:10)
> at com.documents4j.job.AbstractFutureWrappingPriorityFuture.get(AbstractFutureWrappingPriorityFuture.java:205)
> at com.documents4j.job.AbstractFutureWrappingPriorityFuture.get(AbstractFutureWrappingPriorityFuture.java:10)
> at downloadbatimp.doGet(downloadbatimp.java:145)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
> at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
> at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
> at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
> at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
> at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
> at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
> at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
> at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> at java.base/java.lang.Thread.run(Thread.java:832) Caused by: com.documents4j.throwables.ConverterAccessException: The converter
> seems to be shut down
> at com.documents4j.util.Reaction$ConverterAccessExceptionBuilder.make(Reaction.java:117)
> at com.documents4j.util.Reaction$ExceptionalReaction.apply(Reaction.java:75)
> at com.documents4j.conversion.ExternalConverterScriptResult.resolve(ExternalConverterScriptResult.java:70)
> at com.documents4j.conversion.ProcessFutureWrapper.evaluateExitValue(ProcessFutureWrapper.java:48)
> at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:36)
> at com.documents4j.conversion.ProcessFutureWrapper.get(ProcessFutureWrapper.java:11)
> at com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:78)
> at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
> at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)