Documents4j - Tomcat7上的ConversionInputException

时间:2017-06-05 17:14:07

标签: java documents4j

我正在尝试将下载的DOCX文件转换为PDF,并在Tomcat7上部署应用程序,但每次尝试都失败了:

18:16:26.286 [pool-5-thread-3] INFO  c.d.c.msoffice.MicrosoftWordBridge - Requested conversion from .\docTemp\880943b5-769a-4f30-bbe2-5256997e5be3\temp5 (application/vnd.com.documents4j.any-msword) to .\docTemp\880943b5-769a-4f30-bbe2-5256997e5be3\temp6 (application/pdf)
18:16:26.286 [pool-5-thread-3] DEBUG o.z.exec.ProcessExecutor - Executing [cmd, /S, /C, ""C:\Program Files\Apache Software Foundation\Tomcat 7.0\.\docTemp\word_convert1683097585.vbs" "C:\Program Files\Apache Software Foundation\Tomcat 7.0\.\docTemp\880943b5-769a-4f30-bbe2-5256997e5be3\temp5" "C:\Program Files\Apache Software Foundation\Tomcat 7.0\.\docTemp\880943b5-769a-4f30-bbe2-5256997e5be3\temp6" "17""] in .\docTemp.
18:16:26.286 [pool-5-thread-3] DEBUG o.z.exec.ProcessExecutor - Started java.lang.ProcessImpl@63ef6686
18:16:26.333 [WaitForProcess-java.lang.ProcessImpl@63ef6686] DEBUG o.zeroturnaround.exec.WaitForProcess - java.lang.ProcessImpl@63ef6686 stopped with exit code -2
com.documents4j.throwables.ConversionInputException: The input file seems to be corrupt
                at com.documents4j.util.Reaction$ConversionInputExceptionBuilder.make(Reaction.java:159)
                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.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                at java.lang.Thread.run(Unknown Source)

当我尝试使用Web应用程序中使用的相同库/类手动转换文件(在控制台中)时,一切正常但直接在webapp中转换失败。我是否尝试直接转换输入流或首先在本地保存文件然后将其转换为文件(这意味着输入流/文档很好)并不重要。 我正在使用以下单例(删除不必要的代码):

public static DocumentHelper getInstance() throws IOException{
    if (INSTANCE == null)
        INSTANCE = new DocumentHelper();
    return INSTANCE;
}

public DocumentHelper() throws IOException{
        this.appProps = new Properties();
        this.appProps.load(this.getClass().getClassLoader().getResourceAsStream("layer.properties"));
        new File(this.appProps.getProperty(CONVERTIOR_TEMP_DIR)).mkdir();
        this.converter = LocalConverter.builder()
                .baseFolder(new File(this.appProps.getProperty(CONVERTIOR_TEMP_DIR)))
                .workerPool(20, 25, 5, TimeUnit.SECONDS)
                .processTimeout(15, TimeUnit.SECONDS)
                .build();
    }

public byte[] convertDocument(InputStream wordFile){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    converter.convert(wordFile).as(DocumentType.MS_WORD)
                            .to(baos).as(DocumentType.PDF)
                            .execute();
    return baos.toByteArray();
}

0 个答案:

没有答案