1

I'm working at a project and I really want to convert a docx file (placed on the server) to pdf through coldfusion. On the server is lucee installed. I have tried many, maaany things but I hope somebody knows the answer. (I'm also new to coldfusion, so this makes it even harder)

So what have I tried so far?

We already use a plugin called docx4j to automatically fill-in word documents and save them through cf. This works great so the plugin is also working. But if I try to run the following code:

    pdffile = createObject("java", "java.io.File").init(Path_en_bestand_doel_pdf);
    os = null;
    document = createObject("java","org.docx4j.openpackaging.packages.WordprocessingMLPackage").load(createObject("java", "java.io.File").init(Path_en_bestand_oorsprong));
    Docx4J = createObject("java", "org.docx4j.Docx4J");
    fo = Docx4J.createFOSettings();
    fo.setFoDumpFile(createObject("java", "java.io.File").init(Path_en_bestand_oorsprong & ".fo"));
    fo.setWmlPackage(document);
    os = createObject("java", "java.io.FileOutputStream").init(pdffile);
    Docx4J.toFO(fo, os, Docx4J.FLAG_EXPORT_PREFER_XSL);

It gives an error "Exception exporting package". I have tried every combination of the examples I've found online. I have tried multiple older versions. But with no luck. (the hard part is that nobody tries to do it with javascript, but with java)

So after searching online I also found the coldfusion option cfdocument. In the documentation stands that it should be possible to convert doc (and I hope docx) to pdf. This is the code I run

<cfdocument 
    format="pdf" 
    srcfile="#Path_en_bestand_oorsprong#" 
    filename="#Path_en_bestand_doel_pdf#"
    overwrite=true
    pagetype="a4"
    fontembed="true"></cfdocument>

The output for this, if we take a very simple docx file, is a big pdf file with lots of weird symbols. Looks like a character set problem, but could find anymore information how to solve this.

So does anybody have a clue what could be wrong? Or does anybody has an other solution how to simply convert a docx file to pdf?

I hope this is readable and that there is an answer to this. I have also included the error message for the first problem below:

Exception exporting package
at org.docx4j.utils.ResourceUtils.getResource(ResourceUtils.java:86):86
at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.loadDefaultTemplates(AbstractXsltExporterDelegate.java:97):97
at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.getDefaultTemplate(AbstractXsltExporterDelegate.java:85):85
at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.getTemplates(AbstractXsltExporterDelegate.java:76):76
at org.docx4j.convert.out.common.AbstractXsltExporterDelegate.process(AbstractXsltExporterDelegate.java:64):64
at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:63):63
at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:32):32
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:79):79
at org.docx4j.Docx4J.toFO(Docx4J.java:466):466
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):-2
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62):62
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43):43
at java.lang.reflect.Method.invoke(Method.java:497):497
at lucee.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:55):55
at lucee.runtime.java.JavaObject.call(JavaObject.java:237):237
at lucee.runtime.java.JavaObject.call(JavaObject.java:259):259
at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742
at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1590):1590
at bmt_opsys_nl644.modules.documenten.doe_pdfconvert_cfm$cf.call(C:\inetpub\wwwroot\bmt.opsys.nl\modules\documenten\doe_pdfconvert.cfm:76):76
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:922):922
at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:56):56
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:36):36
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2262):2262
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2225):2225
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:456):456
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:47):47
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729):729
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291):291
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52):52
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239):239
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217):217
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106):106
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502):502
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142):142
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79):79
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88):88
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518):518
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:844):844
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673):673
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500):1500
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456):1456
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142):1142
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617):617
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61):61
at java.lang.Thread.run(Thread.java:745):745

After the answer given bellow I get a new error saying something about the fonts. (Could not initialize class org.docx4j.fonts.microsoft.MicrosoftFontsRegistry) I will try some things, but this is the full error:

Could not initialize class org.docx4j.fonts.microsoft.MicrosoftFontsRegistry
at org.docx4j.fonts.PhysicalFonts.getBoldForm(PhysicalFonts.java:480):480
at org.docx4j.fonts.Mapper.getBoldForm(Mapper.java:276):276
at org.docx4j.fonts.fop.util.FopConfigUtil.declareFonts(FopConfigUtil.java:138):138
at org.docx4j.fonts.fop.util.FopConfigUtil.createDefaultConfiguration(FopConfigUtil.java:88):88
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.setupApacheFopConfiguration(FORendererApacheFOP.java:168):168
at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:111):111
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:139):139
at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:47):47
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:82):82
at org.docx4j.Docx4J.toFO(Docx4J.java:466):466
at org.docx4j.convert.out.fo.FOPAreaTreeHelper.getAreaTreeViaFOP(FOPAreaTreeHelper.java:193):193
at org.docx4j.convert.out.fo.LayoutMasterSetBuilder.fixExtents(LayoutMasterSetBuilder.java:136):136
at org.docx4j.convert.out.fo.LayoutMasterSetBuilder.appendLayoutMasterSetFragment(LayoutMasterSetBuilder.java:178):178
at org.docx4j.convert.out.fo.FOExporterVisitorDelegate.appendDocumentHeader(FOExporterVisitorDelegate.java:50):50
at org.docx4j.convert.out.fo.FOExporterVisitorDelegate.appendDocumentHeader(FOExporterVisitorDelegate.java:34):34
at org.docx4j.convert.out.common.AbstractVisitorExporterDelegate.process(AbstractVisitorExporterDelegate.java:82):82
at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:63):63
at org.docx4j.convert.out.common.AbstractWmlExporter.process(AbstractWmlExporter.java:32):32
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:79):79
at org.docx4j.Docx4J.toFO(Docx4J.java:466):466
4

0 回答 0