the pdf export does not work in the the java Uno framework withing Tomcat.

Bertrand Vuaridel bv at artegis.com
Tue Jun 5 09:56:35 PDT 2012


The filter "writer_pdf_Export" does not works while another filter "MS 
Word 97" does, using the java Uno  framework within Tomcat.
e.g. the conversion odt > doc or docx > doc works well
Simply changing  the filter name from "MS Word 97" to 
"writer_pdf_Export" and the target file extensions doc to pdf does not 
work!
The conversion to pdf produce a com.sun.star.task.ErrorCodeIOException 
...  as shonw below.

The same code executed has a standalone java application using the 
loader com.sun.star.lib.loader.Loader is working for both filters! We 
have checked all possible write permission and found no possible issue 
since all processes belong to the same user.

Context: MacOS Lion, LibreOffice3.5.4 Java-Tomcat

Note that  the command line with the writer_pdf_Export filter pdf works 
well!:
/Applications/LibreOffice.app/Contents/MacOS/soffice --headless 
--convert-to pdf:writer_pdf_Export *.docx

Libreoffice  is launched with the command line:
/Applications/LibreOffice.app/Contents/MacOS/soffice --norestore 
--nofirststartwizard --nologo --headless 
--accept=socket,host=localhost,port=7396;urp

The code follows after the exception.

The exception:
com.sun.star.task.ErrorCodeIOException:
     at 
com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:177)
     at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:143)
     at 
com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:338)
     at 
com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:307)
     at 
com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:91)
     at 
com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:640)
     at 
com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:150)
     at 
com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:132)
     at $Proxy8.storeAsURL(Unknown Source)
     at 
com.artegis.rs.pdf.PdfGenerator.convert2pdfWithDaemon(PdfGenerator.java:622)
     at com.artegis.rs.pdf.PdfGenerator.getPdfFile(PdfGenerator.java:299)
     at com.artegis.rs.servlet.UploadServlet.doPost(UploadServlet.java:442)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at 
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
     at 
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
     at 
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
     at 
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
     at 
com.artegis.infra.classes.PageForwarder.forward(PageForwarder.java:234)
     at 
com.artegis.infra.servlet.ControllerServlet.doControl(ControllerServlet.java:1453)
     at 
com.artegis.infra.servlet.ControllerServlet.doPost(ControllerServlet.java:775)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
     at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
     at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
     at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
     at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
     at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
     at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
     at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
     at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
     at java.lang.Thread.run(Thread.java:680)

The Java code:
/*
  * java 
-Dcom.sun.star.lib.loader.unopath="/Applications/LibreOffice.app/Contents/MacOS/" 
-classpath 
:Users/bv/apache-tomcat-6.0.29/lib/ridl.jar:Users/bv/apache-tomcat-6.0.29/lib/unoil.jar:Users/bv/apache-tomcat-6.0.29/lib/juh.jar:Users/bv/apache-tomcat-6.0.29/lib/jurt.jar:.:/Users/bv/Downloads/ 
com.sun.star.lib.loader.Loader test.Test
  */
package test;
import java.io.File;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public class Test {
     public static void main(String[] args) {
         try {
             File file = new 
File("/opt/regis/base/root/templates/docx/invoice/events/invoice.docx");

             XComponentContext xContext = 
Bootstrap.createInitialComponentContext(null);
             XMultiComponentFactory xLocalServiceManager = 
xContext.getServiceManager();
             Object urlResolver = 
xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", 
xContext);
             XUnoUrlResolver xUrlResolver = (XUnoUrlResolver) 
UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver);
             Object initialObject = 
xUrlResolver.resolve("uno:socket,host=localhost,port=7396;urp;StarOffice.ServiceManager");
             XMultiComponentFactory xOfficeFactory = 
(XMultiComponentFactory) 
UnoRuntime.queryInterface(XMultiComponentFactory.class, initialObject);
             Object desktop = 
xOfficeFactory.createInstanceWithContext("com.sun.star.frame.Desktop", 
xContext);
             XComponentLoader xCompLoader = (XComponentLoader) 
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
             String sOutputDir = "/tmp/PDFdaemon";
             File outdir = new File(sOutputDir);
             String sOutUrl = 
"file:///"+outdir.getAbsolutePath().replace('\\', '/');
             String sUrl = 
"file:///"+file.getAbsolutePath().replace('\\', '/');

             // Loading the wanted document
             PropertyValue propertyValues[] = new PropertyValue[1];
             propertyValues[0] = new PropertyValue();
             propertyValues[0].Name = "Hidden";
             propertyValues[0].Value = new Boolean(true);

             Object oDocToStore = xCompLoader.loadComponentFromURL(sUrl, 
"_blank", 0, propertyValues);

             // Getting an object that will offer a simple way to store
             // a document to a URL.
             XStorable xStorable = (XStorable) 
UnoRuntime.queryInterface(XStorable.class, oDocToStore);

             // Preparing properties for converting the document
             propertyValues = new PropertyValue[2];
             // Setting the flag for overwriting
             propertyValues[0] = new PropertyValue();
             propertyValues[0].Name = "Overwrite";
             propertyValues[0].Value = new Boolean(true);
             //  Setting the filter name
             propertyValues[1] = new PropertyValue();
             propertyValues[1].Name = "FilterName";
             //  propertyValues[1].Value = "MS Word 97"; // OK
             //  String sExtension = "doc";
             propertyValues[1].Value = "writer_pdf_Export";
             String sExtension = "pdf";

             // Appending the favoured extension to the origin document 
name
             int index1 = sUrl.lastIndexOf('/');
             int index2 = sUrl.lastIndexOf('.');
             String sStoreUrl = sOutUrl+sUrl.substring(index1, 
index2+1)+sExtension;

             //  Storing and converting the document
             xStorable.storeAsURL(sStoreUrl, propertyValues);
         }
         catch (Exception e) {
             e.printStackTrace();
         }
         System.exit(0);
     }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120605/f9386e78/attachment.html>


More information about the LibreOffice mailing list