简体   繁体   English

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

[英]Converting docx to pdf via JODConverter and LibreOffice causes error

I have 1000 .docx files that I want to convert to pdf so I have written a program to do this, but I can never get through all 1000 files before an error is thrown. 我有1000个.docx文件,我想转换为pdf所以我编写了一个程序来执行此操作,但我无法在抛出错误之前浏览所有1000个文件。 I start a headless version of LibreOffice using soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;" 我使用soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;"启动了无soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;" LibreOffice soffice --headless --accept="socket,host=127.0.0.1,port=2002;urp;" . I am using LibreOffice 4.2.0.4 and JODConverter 2.2.2. 我使用的是LibreOffice 4.2.0.4和JODConverter 2.2.2。 This is my conversion code (prior to this I just iterate all the .docx files in a directory): 这是我的转换代码(在此之前我只是迭代目录中的所有.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;
    }

I can always convert at least 50 files or so before an error is thrown; 在抛出错误之前,我总是可以转换至少50个文件; this is one of the errors I have had: 这是我遇到的错误之一:

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

Other error examples include: 其他错误示例包括:

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@@"!

and

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

and

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

and

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

In every situation (so far), I have been able to retry the conversion on the docx file where the error occurred and the conversion has been successful. 在任何情况下(到目前为止),我都能够在发生错误并且转换成功的docx文件上重试转换。

I have looked at similar questions on this site but most them are for situations where an error is thrown the first time a conversion is attempted, whereas in my case there are always some successful conversions before a failure. 我在这个网站上查看了类似的问题,但大多数是针对第一次尝试转换时出现错误的情况,而在我的情况下,在失败之前总会有一些成功的转换。 I have also tried using OpenOffice with the same results. 我也试过使用OpenOffice得到相同的结果。 I have tried googling error messages but to no avail. 我试过谷歌搜索错误消息但无济于事。

My question is why are these errors occurring, and what can I do to convert all 1000 docx files? 我的问题是为什么会出现这些错误,我该怎么做才能转换所有1000个docx文件? Also I am aware of docx4j but I need to be able to convert .doc files as well which this does not support. 我也知道docx4j,但我需要能够转换.doc文件,这是不支持的。

I'm working with PHP and using the python script to convert and I faced a problem similar to yours, I had errorCode 283 and SfxBaseModel::impl_store failed: 0x11b. 我正在使用PHP并使用python脚本进行转换,我遇到了类似于你的问题,我有errorCode 283和SfxBaseModel :: impl_store失败:0x11b。

I have an Apache server that runs with apache user and a regular user that runs LibreOffice service, let's say theuser , theuser is on apache group in order to write on tmp folders of my app. 我有一个运行apache用户的Apache服务器和运行LibreOffice服务的普通用户,假设用户用户apache组上,以便在我的应用程序的tmp文件夹上写。 When I convert to pdf I create a folder (let's call it thefolder ) to store the converted file (using mkdir function on PHP) I saw that thefolder hasn't group write permission and I test with other location from terminal (with theuser user) and it works, on thefolder I have errorCode 283, what I did is use umask function in PHP to change the permission for the creation of thefolder . 当我转换为PDF创建一个文件夹(我们称之为thefolder)来存储转换后的文件(使用PHP的mkdir功能),我看到thefolder还没有组的写入权限,我和其他位置测试从终端(与theuser用户)它的工作原理,在文件夹中我有errorCode 283,我所做的是在PHP中使用umask函数来更改创建文件的权限。

Summary: Check permissions on folder in wich you'll put the resulting file 摘要:检查文件夹的权限,您将放置生成的文件

I've had a similar problem. 我有类似的问题。 What solved for me was running soffice as root: 为我解决的是以root身份运行soffice:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM