首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JODConverter问题

JODConverter问题
EN

Stack Overflow用户
提问于 2012-07-26 10:21:01
回答 4查看 9.8K关注 0票数 1

我正在使用JODConverter库V3.0Beta4和Open Office3.4,并试图将一些文件转换为PDF/A-1格式。但是,在办公室管理器进程启动之后,它就会挂起,什么也不会发生。下面是输出:

代码语言:javascript
复制
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

中间的一行是打印输出文件名和输入文件名的输出,中间用冒号分隔,因为您可以看到它们是有效值……

下面是我的转换器类:

代码语言:javascript
复制
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套接字,在我使用套接字之前,转换器工作得很好,但在我换成套接字之后,它开始挂起。我不知道为什么..。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-07-27 21:21:30

问题可能出在这里:

代码语言:javascript
复制
officeManager.start(); // may tweak the start and stop code ...

如果代码正在等待启动的进程完成,它可能会等到您终止OpenOffice服务后,它会使程序的其余部分失败。确保在后台服务中启动服务,这样主程序才能继续运行。或者手动启动OpenOffice服务器(在程序之外)。不要使用waitFor(),因为服务永远不会结束。

上面的System.out.println()已经打印出来了,所以到目前为止它还在工作。

票数 4
EN

Stack Overflow用户

发布于 2012-07-30 11:40:52

问题在重启电脑后自动解决了,我不知道为什么...

票数 3
EN

Stack Overflow用户

发布于 2012-07-31 20:23:06

我们一直在开发一个具有即时转换能力的项目,我们也遇到了这个奇怪的问题。解决方案是使用sigar进程管理器而不是纯java进程管理器。它更健壮,更一致,但它需要本机库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11661422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档