2012-07-26 36 views
1

我正在使用JODConverter库V 3.0 Beta 4以及Open Office 3.4,并试图将某些文件转换为PDF/A-1格式。然而,在办公室经理流程启动后,它只是挂起而没有任何反应。下面是输出:JODConverter问题

Jul 26, 2012 12:04:03 PM org.artofsolving.jodconverter.office.ProcessPoolOfficeManager <init> 
INFO: ProcessManager implementation is PureJavaProcessManager 

C:\Users\Chris\AppData\Local\Temp\ArFile\PDF\blah.pdf : C:\Users\Chris\Documents\blah.txt 

Jul 26, 2012 12:04:04 PM org.artofsolving.jodconverter.office.OfficeProcess start 
INFO: starting process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' and profileDir 'C:\Users\Chris\AppData\Local\Temp\.jodconverter_socket_host-127.0.0.1_port-2002' 
Jul 26, 2012 12:04:04 PM org.artofsolving.jodconverter.office.OfficeProcess start 
INFO: started process 

中间的线没有打印输出文件名,并用冒号分隔,你可以看到他们是有效值输入文件名的输出...

这里是我的转换器类:

package com.allcare.arfile; 

import com.sun.star.beans.PropertyValue; 
import java.io.File; 
import java.util.HashMap; 
import java.util.Map; 
import org.artofsolving.jodconverter.OfficeDocumentConverter; 
import org.artofsolving.jodconverter.document.DocumentFamily; 
import org.artofsolving.jodconverter.document.DocumentFormat; 
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration; 
import org.artofsolving.jodconverter.office.OfficeManager; 


public class FileConverter 
{ 
OfficeManager officeManager; 
String tempFilePath; 

public FileConverter() 
{ 
    officeManager = new DefaultOfficeManagerConfiguration() 
      //.setRetryTimeout(30000L) 
      //.setTaskExecutionTimeout(60000L) 
      .buildOfficeManager(); 
    tempFilePath = System.getProperty("java.io.tmpdir") + "\\ArFile\\PDF\\"; 
} 

// if possible this function converts a file to a PDF/A-1 compliant file 
public File convertToPdf(File inputFile, Log logger, User user) 
{   
    if (isConvertableToPDF(inputFile.getName())) // REMEMBER TO CHANGE THE IF STATEMENT IN THE createMetadata() section to reflect this 
    { 
     new File(tempFilePath).mkdirs(); 
     String filename = inputFile.getName(); 
     filename = filename.substring(0, filename.lastIndexOf(".")); 

     File outputFile = new File(tempFilePath + filename + ".pdf"); 

     System.out.println(outputFile + " : " + inputFile); 

     officeManager.start(); // may tweak the start and stop code to appear elsewhere for additional efficiency 

     DocumentFormat docFormat = new DocumentFormat("Portable Document Format", "pdf", "application/pdf"); 
     Map map = new HashMap(); 
     map.put("FilterName", "writer_pdf_Export"); 
     PropertyValue[] aFilterData = new PropertyValue[1]; 
     aFilterData[0] = new PropertyValue(); 
     aFilterData[0].Name = "SelectPdfVersion"; 
     aFilterData[0].Value = 1; 
     map.put("FilterData", aFilterData); 
     docFormat.setStoreProperties(DocumentFamily.TEXT, map); 

     OfficeDocumentConverter docConverter = new OfficeDocumentConverter(officeManager); 
     docConverter.convert(inputFile, outputFile, docFormat); 

     officeManager.stop(); 

     return outputFile; 
    } 

    return inputFile; 
} 

// returns true if the file format is known to be convertible into the PDF/A-1 format 
public boolean isConvertableToPDF(String filename) 
{ 
    if (filename.endsWith(".doc") || filename.endsWith(".txt") || filename.endsWith(".xls") 
      || filename.endsWith(".ppt") || filename.endsWith(".docx")) 
    { 
     return true; 
    } 

    return false; 
} 

} 

我用java插座,之前我用的插座转换器工作得很好,但之后,我改变插座就开始挂起。我不知道为什么...

回答

3

这个问题可能是在这里:

officeManager.start(); // may tweak the start and stop code ... 

如果代码正在等待启动过程完成,也可能等到你杀了OpenOffice的服务后,它失败程序的其余部分。 请确保您在后台服务中启动服务,以便主程序可以继续。或者手动启动OpenOffice服务器(在程序外部)。不要waitFor(),因为服务永远不会结束。

上面的System.out.println()确实打印完毕,所以到目前为止它还在工作。

+0

好的,我应该什么时候调用start()以及如何将它作为后台进程运行?我应该在启动我的程序时调用它,然后在程序执行完成后将其杀掉。 – 2012-07-30 00:47:12

+0

我现在尝试使用一个非常简单的例子,就像他们在他们的网站上给出的例子。程序在start()函数后仍然挂起。我试图重新安装JODConverter和Open Office都没有成功,似乎决定不工作......某些地方我认为有什么地方出现了问题.. – 2012-07-30 02:08:31

3

的问题解决了自身重新启动计算机后,我不知道为什么....

0

我们一直在开发一个项目,这对即时转换功能,同时,我们也过这个奇怪的问题绊倒。解决方案是使用使用sigar进程管理器而不是纯java进程管理器。它更健壮,更一致,但它需要本地库。

0

似乎它是你选择的端口的问题,我知道我使用java套接字对象碰到类似这样的时髦东西。

+0

我认为它产生了JODConverter服务,我不得不强制终止这个过程时间和即时猜测,这一定是造成了一个问题。 – 2012-08-06 00:34:29