通过JODConverter和LibreOffice将docx转换为pdf会导致错误

6
我有1000个.docx文件需要转换成pdf,因此我编写了一个程序来完成这个任务,但是在所有1000个文件都处理完之前就会出现错误。我使用soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;"启动了LibreOffice的无头版本。我使用的是LibreOffice 4.2.0.4和JODConverter 2.2.2。这是我的转换代码(在此之前,我只是迭代目录中的所有.docx文件):
try {
        File inputFile = new File(sourceFile);
        if (!inputFile.exists()) {
            return -1;
        }

        File outputFile = new File(destFile);
        OpenOfficeConnection connection = new SocketOpenOfficeConnection(host_Str, 
            Integer.parseInt(port_Str));
        connection.connect();
        DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
        converter.convert(inputFile, outputFile);

        connection.disconnect();

        return 0;
    }

    catch (ConnectException e) {
        System.out.println("Openoffice listener exception!");
        return 1;
    }

在出现错误之前,我通常可以转换至少50个文件; 这是我遇到的其中一个错误:

Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: 
    conversion failed: could not save output document; OOo errorCode: 3088
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(OpenOfficeDocumentConverter.java:142)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.convertInternal(OpenOfficeDocumentConverter.java:120)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:104)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:74)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:70)
at previews.ConvertToPdfJOD.office2PDF(ConvertToPdfJOD.java:119)
at previews.ConvertToPdfJOD.beginConvert(ConvertToPdfJOD.java:91)
at previews.ConvertToPdfJOD.main(ConvertToPdfJOD.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Caused by: com.sun.star.task.ErrorCodeIOException: SfxBaseModel::impl_store <file:///C:/dev/testFiles/docx/newsletter_t3w7-2012.docx.pdf> failed: 0xc10
at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:182)
at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:148)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:344)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:313)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:101)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:652)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:154)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:136)
at com.sun.proxy.$Proxy8.storeToURL(Unknown Source)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.storeDocument(OpenOfficeDocumentConverter.java:156)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(OpenOfficeDocumentConverter.java:140)
... 12 more

其他错误示例包括:
Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: 
    conversion failed: could not save output document

Caused by: com.sun.star.uno.RuntimeException: [msci_uno bridge error] 
    UNO type of C++ exception unknown: "std.bad_alloc", RTTI-name=".?AVbad_alloc@std@@"!

并且

Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: 
    conversion failed: could not save output document; OOo errorCode: 283

Caused by: com.sun.star.task.ErrorCodeIOException: SfxBaseModel::impl_store 
    <file:///R:/document%20preview%20DY/speedTests/doc/cm9draftfinallist.doc.pdf> failed: 0x11b

并且

Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: 
    conversion failed: could not load input document

Exception in thread "main" com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: 
    conversion failed: could not save output document; OOo errorCode: 3088

Caused by: com.sun.star.task.ErrorCodeIOException: SfxBaseModel::impl_store 
    <file:///C:/dev/testFiles/docx/newsletter_t3w7-2012.docx.pdf> failed: 0xc10

在目前的每种情况下,我都能够重新尝试转换发生错误的docx文件,而且转换成功了。
我查看了此网站上类似的问题,但大多数情况是第一次尝试转换时会抛出错误,而在我的情况下,在失败之前总会有一些成功的转换。我也尝试使用OpenOffice,结果相同。我尝试过谷歌搜索错误消息,但没有结果。
我的问题是为什么会发生这些错误,以及我该如何转换所有1000个docx文件?另外,我知道docx4j,但我需要能够转换.doc文件,而它不支持这一点。
2个回答

3

我正在使用PHP并使用python脚本进行转换,遇到了与您类似的问题。 我遇到了283错误代码和SfxBaseModel :: impl_store失败:0x11b。

我有一个Apache服务器,以apache用户运行,并且有一个常规用户运行LibreOffice服务,假设是theuser,为了写入我的应用程序的tmp文件夹,theuser属于apache组。 当我转换为pdf时,我创建一个文件夹(称之为thefolder)来存储转换后的文件(使用PHP上的mkdir函数),我发现thefolder没有组写入权限,并在终端上使用theuser用户测试了其他位置,它可以工作,在thefolder中,我遇到了错误代码283,我所做的是在PHP中使用umask函数更改了创建thefolder的权限。

总结:检查将放置结果文件的文件夹的权限。


我没有使用任何文件夹,而是使用ByteStream,即使使用chmod 777也显示相同的错误。 - 3xCh1_23

-1

我曾经遇到过类似的问题。解决方法是以root身份运行soffice:

soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接