I need to convert a set of docx files to PDF's. So I executed the following piece of code I found on one of the forum posts:
- Code: Select all
File dir = new File( "c:/mydocxfiles");
for ( File f : dir.listFiles() ) {
if ( ! f.getAbsolutePath().endsWith( "docx" ) )
continue;
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(f);
String out= f.getAbsolutePath() + ".pdf";
java.io.File temp = new File(out);
OutputStream os = new java.io.FileOutputStream(temp);
wordMLPackage.pdf(os);
os.close();
}
It loads up the WordprocessingMLPackage just fine, but when it tries to output it as a PDF it throws:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/xml/bind/marshaller/NamespacePrefixMapper
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
In one of the previous forum posts there is a reference to this class by a person who is using Java 5, but I am compiling and executing under Java 6. I do see that NamespacePrefixMapper is part of the docx4j.jar file as well as coming with the Java 6 libraries. So I ordered the jar files in the eclipse "Order and Export" tab to have docx4j.jar to be at the top and I still see the exception. Any help would be appreciated.
Also, where is the best place to see the source for the examples? To just browse the source? or is there a wiki page with instructions?