2016-03-04 109 views
1

我意識到jodconverter已經被廢棄了一段時間了,但人們仍然在報告它是用於docx到pdf轉換的工具。我試圖讓它在我的Clojure應用程序中轉換某些模板docx。從命令行它很好:JOD Converter to pdf API不知道docx?

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 

而且輸出是偉大的。不過,我似乎無法得到的東西從我的應用程序,這是在Clojure的工作,並試圖在這裏遵循的方向:http://www.artofsolving.com/opensource/jodconverter/guide/scripting-languages.html

我REPL會話如下所示:

my-app.users> (def connection (SocketOpenOfficeConnection.)) 
     #'my-app.users/connection 
my-app.users> connection 
     #object[com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection 0x4f3c5073 "com.artofsolvin[email protected]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 "[email protected]"] 
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 

由於你可以看到,問題是最後一點:由於某種原因,它似乎並不瞭解docx格式,儘管CLI運行良好。我怎樣才能讓API合作得很好?

+0

嗯......當應用程序使用2.2.1(Maven上的最新版本)時,這可能與CLI版本2.2.2有關。 –

回答

0

這個問題確實出現在版本中:儘管JOD轉換器網站的確如此,Maven並沒有2.2版本。我通過將2.1 POM文件複製到leiningen自動創建的2.2目錄中,並用新版本信息調整POM來製作本地Maven回購。我粘貼了來自網站的2.2 JAR。之後,它運行良好,失蹤班正常工作。