我有 1000 个要转换为 pdf 的 .docx 文件,所以我编写了一个程序来执行此操作,但在引发错误之前我永远无法通过所有 1000 个文件。我使用soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;"
. 我正在使用 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 文件。