0

I am trying to convert downloaded DOCX file into PDF with application deployed on Tomcat7, but every attempt fails with:

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)

When I try to convert file manually (in console) with the same libraries/classes used in web application, everything works fine but converting directly in webapp fails. It doesn't matter whether I tried to convert input stream directly or save file locally first and then convert it as file (which means that input stream/document is fine). I am using following singleton (removed unnecessary code):

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();
}
Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
mi0
  • 166
  • 9
  • Note: I tried the same web application on my computer and everything worked without problem. So this looks like some specific problem with environment, but I have no clue what to check. There is freshly installed JRE and Tomcat so maybe some security issue? In working directory is created VBS file with some subdirectory, but no documents... – mi0 Jun 06 '17 at 12:32
  • Note 2: The problem is in Tomcat, specifically in the way it was launched. If it is started via commad line with start.bat, everything works fine. If it was launched as windows service or via windows scheduler (which execute "start.bat" file), it cause this problem. Tried to run as administrator or user but without success. Wth? – mi0 Jun 06 '17 at 17:06
  • Note 3: Ok, seems to be the same problem as here: [https://stackoverflow.com/questions/28760670/how-to-schedule-documents4j-server-standalone-as-windows-service-using-procrun ] – mi0 Jun 06 '17 at 19:12

0 Answers0