Reputation: 21
I have a problem converting from .docx to .pdf with the Documents4j library, which only happens when I run the application from apache tomcat installation.
However, if the application is executed with Eclipse or XAMPP apache tomcat works correctly.
I have tried Windows 10, Windows 7 and Windows Server 2012 with apache tomcat 8 and 8.5 but the problem persist.
Eclipse or XAMPP do "something" when running apache tomcat that makes it work correctly
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:
<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>
Error:
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)
Upvotes: 2
Views: 458
Reputation: 44042
You can try to specify an explicit base folder for the converter. Application containers often define an implicit temporary folder that is different from the default temporary folder, maybe your setup forbids execution of scripts from within this folder what might cause your troubles. You can check the temporary folder by checking the java.io.tmpdir
property at runtime.
As another problem, make sure that your base folder does not contain any spaces. Please update to 1.0.3, too, where the update contains improved handling of such spaces. Maye Tomcat is installed in "Program Files" which might be the problem.
Upvotes: 1