2

(SOLVED) I want to convert a docx-document into pdf. As the results with xdocreport weren't quite statisfactory, I tried out documents4j. Unfortunalty, I recieve the following 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

My first guess would be that it put one extra pair of quotation marks around the path (cmd, /S, /C, ""F:\word_start199932774.vbs""). Is there anything I can do about that or is there something else I do wrong?

Any help is welcome, thanks a lot in advance.

UPDATE:

I found my mistake, instead of this line:

IConverter converter = LocalConverter.builder().baseFolder(new File("")).workerPool(20, 25, 1, TimeUnit.SECONDS).processTimeout(5, TimeUnit.SECONDS).build();

I need to use this line:

IConverter converter = LocalConverter.builder().baseFolder(base).workerPool(20, 25, 1, TimeUnit.SECONDS).processTimeout(5, TimeUnit.SECONDS).build();

with base being a temporary directory. My bad.

Starjon
  • 21
  • 4
  • 3
    Please do not edit the resolution into the question but create an own answer for it which you can accept some time later. This allows the system to recognize the question as solved. – mkl May 04 '17 at 16:22
  • 1
    such error could occur when you trying to make the conversion on Unix machine. Be aware, the lib requires MS components to be installed. https://github.com/documents4j/documents4j/issues/41 – Serhii Povísenko Jun 17 '20 at 15:59
  • 1
    indeed, as @SerhiiPovísenko said, this library is not working in unix based systems(facepalm!). – brebDev Dec 08 '21 at 12:00
  • @brebDev mate I advise you to use Gotenberg then. It will save you a lot of time https://stackoverflow.com/a/62434880/2852528 – Serhii Povísenko Dec 08 '21 at 17:12

0 Answers0