AnsweredAssumed Answered

Word to PDF: NullPointerException in JODConverter

Question asked by nicolasraoul on Mar 10, 2010
Latest reply on Oct 25, 2010 by neilm
In Java, I transform a Word file to a PDF file, but get a NullPointerException in jodconverter. It seems that officeManager is null. Here is the exception:

org.alfresco.service.cmr.repository.ContentIOException: 02100003 Content conversion failed: 
   reader: ContentAccessor[ contentUrl=store://2010/3/10/13/59/458146e2-60db-4cf1-91fb-b93ab70aa4d3.bin, mimetype=application/msword, size=9216, encoding=UTF-8, locale=ja_JP]
   writer: ContentAccessor[ contentUrl=store://2010/3/10/14/0/a2d01abf-d7d5-48cf-b3d3-d3e4948cac30.bin, mimetype=application/pdf, size=0, encoding=UTF-8, locale=ja_JP]
   options: org.alfresco.service.cmr.repository.TransformationOptions@17af7af
   at org.alfresco.repo.content.transform.AbstractContentTransformer2.transform(AbstractContentTransformer2.java:176)
   at org.alfresco.repo.content.transform.AbstractContentTransformer2.transform(AbstractContentTransformer2.java:143)
   at com.company.PublishActionHandler$4.doWork(PublishActionHandler.java:185)

   at org.jbpm.graph.def.Action.execute(Action.java:129)
   at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:284)
   … 95 more
Caused by: java.lang.NullPointerException
   at org.artofsolving.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:75)
   at org.artofsolving.jodconverter.OfficeDocumentConverter.convert(OfficeDocumentConverter.java:66)
   at org.alfresco.enterprise.repo.content.transform.JodContentTransformer.transform(JodContentTransformer.java:228)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.alfresco.repo.management.subsystems.SubsystemProxyFactory$1.invoke(SubsystemProxyFactory.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy34.transform(Unknown Source)
   at org.alfresco.repo.content.transform.ProxyContentTransformer.transformInternal(ProxyContentTransformer.java:66)
   at org.alfresco.repo.content.transform.AbstractContentTransformer2.transform(AbstractContentTransformer2.java:167)
   … 112 more

And here is my code:

       ContentReader reader = contentService.getReader(original, ContentModel.PROP_CONTENT);
       ContentWriter pdfWriter = contentService.getWriter(pdf, ContentModel.PROP_CONTENT, true);
       ContentTransformer pdfTransformer =
              contentService.getTransformer(originalMimeType, MimetypeMap.MIMETYPE_PDF);
      
       // Transform as admin, because the place where we write might require high privileges.
       final ContentTransformer finalPdfTransformer = pdfTransformer;
       final ContentReader finalReader = reader;
       final ContentWriter finalPdfWriter = pdfWriter;
      RunAsWork<Boolean> work2 = new RunAsWork<Boolean>() {
           public Boolean doWork() throws Exception {
              finalPdfTransformer.transform(finalReader, finalPdfWriter);
              return true;
            }
        };
        AuthenticationUtil.runAs(work2, "admin");

Word to PDF transformation works fine as a content rule, but does not work with this Java code.

Any idea?
Maybe a sort of connection with OpenOffice is sometimes lost?
Thanks a lot!

Outcomes