Documents4j IllegalStateException

208 views
Skip to first unread message

axi...@gmail.com

unread,
Dec 29, 2016, 4:37:04 AM12/29/16
to documents4j

im trying to use documents4j (https://bintray.com/raphw/maven/documents4j) in order to convert a docx file to pdf with this code: Thank you very much in advance, i have no idea of making it works

    package documents4j;


import java.io.File;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;


public class HelloPDF {
    public static void main(String[] args) {

        File wordFile = new File("c:/datos/Resultados.docx"), target = new File("c:/datos/Resultados.pdf");

        IConverter converter = LocalConverter.builder().baseFolder(new File("c:/datos/"))
                .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)
                // .prioritizeWith(1000) // optional
                .schedule();

    }
}

But im encountering an illegalstateexcepcion

Exception in thread "main" 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 documents4j.HelloPDF.main(HelloPDF.java:20)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.documents4j.conversion.ExternalConverterDiscovery.make(ExternalConverterDiscovery.java:30)
    ... 7 more
Caused by: java.lang.NoClassDefFoundError: com/documents4j/util/Reaction$IExceptionBuilder
    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)
    ... 12 more
Caused by: java.lang.ClassNotFoundException: com.documents4j.util.Reaction$IExceptionBuilder
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 15 more
[Shutdown hook: com.documents4j.job.LocalConverter] INFO com.documents4j.job.ConverterAdapter - Tried to deregister shut down hook in shut down period
java.lang.IllegalStateException: Shutdown in progress
    at java.lang.ApplicationShutdownHooks.remove(ApplicationShutdownHooks.java:82)
    at java.lang.Runtime.removeShutdownHook(Runtime.java:237)
    at com.documents4j.job.ConverterAdapter.deregisterShutdownHook(ConverterAdapter.java:121)
    at com.documents4j.job.ConverterAdapter.cleanUp(ConverterAdapter.java:107)
    at com.documents4j.job.ConverterAdapter.shutDown(ConverterAdapter.java:98)
    at com.documents4j.job.LocalConverter.shutDown(LocalConverter.java:109)
    at com.documents4j.job.ConverterAdapter$ConverterShutdownHook.run(ConverterAdapter.java:134)
Exception in thread "Shutdown hook: com.documents4j.job.LocalConverter" java.lang.NullPointerException
    at com.documents4j.job.LocalConverter.shutDown(LocalConverter.java:100)
    at com.documents4j.job.ConverterAdapter$ConverterShutdownHook.run(ConverterAdapter.java:134)

Btw im using this libraries

Libraries

Rafael Winterhalter

unread,
Dec 29, 2016, 5:24:30 AM12/29/16
to axi...@gmail.com, documents4j
Seems like you are missing the documents4j-util-all dependency.

I would recommend you to manage your dependencies with a build system like Maven where all (transitive) dependencies are imported automatically. All you need to do is to import the local converter and the MS Word bridge as described in the documentation.

Best regards, Rafael

--
You received this message because you are subscribed to the Google Groups "documents4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to documents4j+unsubscribe@googlegroups.com.
To post to this group, send email to docum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/documents4j/90810411-df35-4e7a-ab03-88522c8d3924%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

axi...@gmail.com

unread,
Dec 29, 2016, 6:06:22 AM12/29/16
to documents4j, axi...@gmail.com
It worked, thank you very much!
To unsubscribe from this group and stop receiving emails from it, send an email to documents4j...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages