Pregunta

I'm trying to use docx4j 3.0 to load an existing docx file, make a few simple textual changes and save as PDF. My code looks like this:

        WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load (new File (template));
        MainDocumentPart doc = wordMLPackage.getMainDocumentPart ();

        try
        {
            VariablePrepare.prepare (wordMLPackage);
        }
        catch (Exception e)
        {
            System.err.println ("Warning: VariablePrepare failed: " + e);
        }

                    (here I enumerate all Text nodes and make changes as required)

        PdfConversion c = new Conversion (wordMLPackage);
        try (FileOutputStream out = new FileOutputStream (outputFile)) {
            c.output (out, new PdfSettings ());
        }

This is producing the following exception:

org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:79)
    at org.docx4j.Docx4J.toFO(Docx4J.java:467)
    at org.docx4j.Docx4J.toPDF(Docx4J.java:477)
    at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:70)
    at net.meridiandigital.binco.invoicegen.InvoiceGenerator.generateFile(InvoiceGenerator.java:80)
    at net.meridiandigital.binco.invoicegen.Test.main(Test.java:46)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Exception loading default template "org/docx4j/convert/out/fo/docx2fo.xslt", Cannot convert argument/return type in call to method 'org.docx4j.convert.out.common.XsltCommonFunctions.notImplemented(reference, node-type, string)'
    at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.loadDefaultTemplates(AbstractXsltExporterDelegate.java:92)
    at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.getDefaultTemplate(AbstractXsltExporterDelegate.java:75)
    at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.getTemplates(AbstractXsltExporterDelegate.java:66)
    at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.process(AbstractXsltExporterDelegate.java:57)
    at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:63)
    at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:32)
    at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:71)
    ... 5 more
Caused by: javax.xml.transform.TransformerConfigurationException: Cannot convert argument/return type in call to method 'org.docx4j.convert.out.common.XsltCommonFunctions.notImplemented(reference, node-type, string)'
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:945)
    at org.docx4j.XmlUtils.getTransformerTemplate(XmlUtils.java:842)
    at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.loadDefaultTemplates(AbstractXsltExporterDelegate.java:88)
    ... 11 more

Any ideas what's going wrong?

¿Fue útil?

Solución

It shouldn't be using

com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl

but rather

org.apache.xalan.processor.TransformerFactoryImpl

(You need the real Xalan on your classpath)

See also instantiateTransformerFactory() at line 224 of https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/XmlUtils.java

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top