2012-07-26 38 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