Pergunta

I am using docx4j 2.8.1 and I tried to convert several different docx file, but i have always the same issue. maybe the issue is coming from the version of the library or some dependency missing.

Code:

package test;

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;


public class pdfConverter {
    public static void main(String[] args) {
        createPDF();
    }

    private static void createPDF() {
        try {

            // 1) Load DOCX into WordprocessingMLPackage
            InputStream is = new FileInputStream(
                    new File("D:/TestDoc/Res.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:/TestDoc/Res.pdf"));
            PdfConversion converter = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
                    wordMLPackage);
            converter.output(out, pdfSettings);

        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}

Error:

    org.docx4j.openpackaging.exceptions.Docx4JException: FOP issues
    at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:374)
    at test.pdfConverter.createPDF(pdfConverter.java:42)
    at test.pdfConverter.main(pdfConverter.java:21)
Caused by: java.lang.NullPointerException
    at org.docx4j.XmlUtils.transform(XmlUtils.java:842)
    at org.docx4j.XmlUtils.transform(XmlUtils.java:802)
    at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:349)
    ... 2 more
Foi útil?

Solução

Solved by changing to jars. i used 2.8.0 and its fine now.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top