问题
报错如下:
代码
首先要包管你的Java代码没问题,可以参考下面代码
maven依靠
- <!--documents4j-->
- <dependency>
- <groupId>com.documents4j</groupId>
- <artifactId>documents4j-local</artifactId>
- <version>1.0.3</version>
- </dependency>
- <!-- documents4j-->
- <dependency>
- <groupId>com.documents4j</groupId>
- <artifactId>documents4j-transformer-msoffice-word</artifactId>
- <version>1.0.3</version>
- </dependency>
复制代码 DocxToPdfUtil工具类
测试
- @SpringBootApplication
- public class PdfdemoApplication {
- public static void main(String[] args) {
- //Linux服务器
- String inputFile = "/usr/local/a.docx";
- //本地
- // String inputFile = "C:\\zhushanglin\\test\\a.docx";
-
- DocxToPdfUtil.documents4jWordToPdf(inputFile);
- System.out.println("Done! Pdf ");
- SpringApplication.run(PdfdemoApplication.class, args);
- }
- }
复制代码 发现本地win没问题,到服务器Linux就有问题,缘故起因是 documents4j 使用 Microsft Office 的 APIs 来举行文档转换,因此须要在Linux上安装 OpenOffice/LibreOffice 编辑器
Ubuntu:
- sudo apt-get install libreoffice
复制代码 CentOS:
- sudo yum install libreoffice
复制代码 把这装上后,再测试,发现可以完美转换。
下课!
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |