I am trying to convert a word docx file to a pdf file, all using java, and without any user interaction.
This is my code so far, I am using the docx4j library.
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package richard.fileupload;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.docx4j.convert.out.pdf.PdfConversion;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
/**
 *
 * @author Richard
 */
public class pdfConverter {
        public static void main(String[] args) {
        createPDF();
        createPDF();
    }
    private static void createPDF() {
        try {
            long start = System.currentTimeMillis();
            // 1) Load DOCX into WordprocessingMLPackage
            InputStream is = new FileInputStream(new File(
                    "D:/HelloWorld.docx"));
            WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
                    .load(is);
            // 2) Prepare Pdf settings
            PdfSettings pdfSettings = new PdfSettings();
            // 3) Convert WordprocessingMLPackage to Pdf
            OutputStream out = new FileOutputStream(new File(
                    "D:/HelloWorld.pdf"));
            PdfConversion converter = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
                    wordMLPackage);
            converter.output(out, pdfSettings);
            System.err.println("Generate pdf/HelloWorld.pdf with "
                    + (System.currentTimeMillis() - start) + "ms");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
However I am getting this error when I try to run, it compiles just fine
run:
java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at org.docx4j.openpackaging.Base.<clinit>(Base.java:42)
    at richard.fileupload.pdfConverter.createPDF(pdfConverter.java:32)
    at richard.fileupload.pdfConverter.main(pdfConverter.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    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)
    ... 3 more
java.lang.NoClassDefFoundError: Could not initialize class org.docx4j.openpackaging.packages.WordprocessingMLPackage
    at richard.fileupload.pdfConverter.createPDF(pdfConverter.java:32)
    at richard.fileupload.pdfConverter.main(pdfConverter.java:22)
BUILD SUCCESSFUL (total time: 0 seconds)
any idea what the error is and what is the cause of this?
EDIT I am now getting this error
java.lang.NoClassDefFoundError: org/apache/fop/apps/FopFactory
    at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:231)
    at richard.fileupload.pdfConverter.createPDF(pdfConverter.java:43)
    at richard.fileupload.pdfConverter.main(pdfConverter.java:22)