我在使用 Documents4j 库从 .docx 转换为 .pdf 时遇到问题,这仅在我从 apache tomcat 安装运行应用程序时发生。
但是,如果应用程序使用 Eclipse 或 XAMPP 执行,则 apache Tomcat 可以正常工作。
我已经使用 apache tomcat 8 和 8.5 尝试了 Windows 10、Windows 7 和 Windows Server 2012,但问题仍然存在。
Eclipse 或 XAMPP 在运行 apache tomcat 时会做一些“事情”,使其正常工作
jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="com.documents4j.api.IConverter,
com.documents4j.job.LocalConverter,
com.documents4j.api.DocumentType,
java.io.File" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<%
IConverter converter = LocalConverter.make();
converter.convert(new File("C:\\test\\test.docx")).as(DocumentType.DOCX).to(new File("C:\\test\\test.pdf")).as(DocumentType.PDF).execute();
%>
</body>
</html>
依赖项:
<dependencies>
<!-- Local dependencies -->
<!-- https://mvnrepository.com/artifact/com.documents4j/documents4j-local -->
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-local</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.documents4j/documents4j-transformer-msoffice-word -->
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-transformer-msoffice-word</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
错误:
org.apache.jasper.JasperException: com.documents4j.throwables.ConverterException: Conversion failed for an unknown reason
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:565)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:481)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.documents4j.throwables.ConverterException: Conversion failed for an unknown reason
com.documents4j.job.AbstractFutureWrappingPriorityFuture.run(AbstractFutureWrappingPriorityFuture.java:90)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)