I realize that jodconverter has been derelict for a while now, but people are still reporting it as the tool to be used for docx to pdf conversions. I'm trying to get it working in my Clojure app for converting some template docx. From the commandline it works great:
soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &
java -jar lib/jodconverter-cli-2.2.2.jar $mydocx ~/temp/mydocxout.pdf
And the output is great. However, I can't seem to get things to work from my app, which is in clojure and is trying to follow the directions here: http://www.artofsolving.com/opensource/jodconverter/guide/scripting-languages.html
My REPL session looks like the following:
my-app.users> (def connection (SocketOpenOfficeConnection.))
#'my-app.users/connection
my-app.users> connection
#object[com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection 0x4f3c5073 "com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection@4f3c5073"]
my-app.users> (def connection (SocketOpenOfficeConnection. 8100))
#'my-app.users/connection
my-app.users> (def registry (DefaultDocumentFormatRegistry.))
#'my-app.users/registry
my-app.users> (def converter (OpenOfficeDocumentConverter. connection registry))
#'my-app.users/converter
my-app.users> (def pdf (.getFormatByFileExtension registry "pdf"))
#'my-app.users/pdf
my-app.users> pdf
#object[com.artofsolving.jodconverter.DocumentFormat 0x3bd2e41 "com.artofsolving.jodconverter.DocumentFormat@3bd2e41"]
my-app.users> (def pdf-options {"ReduceImageResolution" true
"MaxImageResolution" 300})
#'my-app.users/pdf-options
my-app.users> (.setExportOption pdf DocumentFamily/TEXT "FilterData" pdf-options)
nil
my-app.users> (def input (io/file "resources/docx-templates/titlepage-image.docx"))
#'my-app.users/input
my-app.users> (def output (io/file "/temp/jodout.pdf"))
#'my-app.users/output
my-app.users> (.convert converter input output pdf)
IllegalArgumentException unknown document format for file: resources/docx-templates/titlepage-image.docx com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.guessDocumentFormat (AbstractOpenOfficeDocumentConverter.java:121)
my-app.users> (def docx (.getFormatByFileExtension registry "docx"))
#'my-app.users/docx
my-app.users> docx
nil
As you can see, the problem is the last bit: it doesn't seem to know about docx format for some reason, though the CLI is working great. How can I get the API to cooperate as nicely?
The problem was indeed in the version: Maven doesn't have 2.2, although the JOD converter website does. I made a local maven repo by copying the 2.1 POM file into the 2.2 directory automatically created by leiningen, and adjusting the POM with new version info. I pasted in the 2.2 JAR that I got from the website. After that, it worked fine and the missing classes functioned properly.