简体   繁体   中英

Doc and Docx to PDF conversion , using Java on Linux

I have a Java code to convert doc,docx to pdf using document4j it work fine on windows, but in linux I have this problem. Can I use this library on linux? Whats alternatives can I have?

The error is

java.io.IOException: Cannot run program "cmd" (in directory "/tmp/1542047549404-0"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) ~[na:1.8.0_171]

2018-11-12 18:32:29.508 ERROR 10831 --- [pool-1-thread-1] c.d.c.msoffice.MicrosoftWordBridge       : Unable to run script: /tmp/1542047549404-0/word_start184242440.vbs

java.io.IOException: Could not execute [cmd, /S, /C, ""/tmp/1542047549404-0/word_start184242440.vbs""] in /tmp/1542047549404-0.
    at org.zeroturnaround.exec.ProcessExecutor.invokeStart(ProcessExecutor.java:936) ~[zt-exec-1.8.jar!/:na]

I think there are several reasons listed on their homepage why conversion cannot work under linux:

[...] the LocalConverter can only be run if:

  • The JVM is run on a MS Windows platform that ships with the Microsoft Scripting Host for VBS (this is true for all contemporary versions of MS Windows.
  • MS Word is installed in version 2007 or higher. PDF conversion is only supported when the PDF plugin is installed. The plugin is included into MS Word from Word 2010 and higher.
  • MS Word is not already running when the LocalConverter starts. This is in particularly true for MS Word instances that are run by another instance of LocalConverter. (As mentioned, be aware that this is also true for instances running on a different JVM or that are loaded by a different class loader.)
  • MS Word is properly activated and configured for the user running the JVM. MS Word does therefore not require any configuration on program startup or any other wizard.
  • When the JVM application which uses the LocalConverter is run as a service, note the information on using MS Word from the MS Windows service profile below.

For alternative approaches see How to convert MS doc to pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM