简体   繁体   English

Doc和Docx到PDF的转换,在Linux上使用Java

[英]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. 我有一个Java代码,可以使用document4j将doc,docx转换为pdf,在Windows上可以正常工作,但是在Linux中,我有这个问题。 Can I use this library on linux? 我可以在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: 我认为他们的主页上列出了几个原因,导致在Linux下无法进行转换:

[...] the LocalConverter can only be run if: [...]仅在以下情况下可以运行LocalConverter:

  • 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. JVM在Microsoft Scripting Host for VBS附带的MS Windows平台上运行(对于所有最新版本的MS Windows都是如此。
  • MS Word is installed in version 2007 or higher. MS Word安装在2007或更高版本中。 PDF conversion is only supported when the PDF plugin is installed. 仅在安装了PDF插件时才支持PDF转换。 The plugin is included into MS Word from Word 2010 and higher. 该插件包含在Word 2010及更高版本的MS Word中。
  • MS Word is not already running when the LocalConverter starts. 启动LocalConverter时,MS Word尚未运行。 This is in particularly true for MS Word instances that are run by another instance of LocalConverter. 对于由LocalConverter的另一个实例运行的MS Word实例尤其如此。 (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.) (如前所述,请注意,对于在不同JVM上运行或由不同类加载器加载的实例也是如此。)
  • MS Word is properly activated and configured for the user running the JVM. 已为运行JVM的用户正确激活并配置了MS Word。 MS Word does therefore not require any configuration on program startup or any other wizard. 因此,MS Word在程序启动或任何其他向导时不需要任何配置。
  • 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. 当使用LocalConverter的JVM应用程序作为服务运行时,请从下面的MS Windows服务配置文件中记录有关使用MS Word的信息。

For alternative approaches see How to convert MS doc to pdf 有关替代方法,请参见如何将MS doc转换为pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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