使用openoffice无头方式将docx转换为pdf太慢 [英] Docx to pdf using openoffice headless way too slow

查看:915
本文介绍了使用openoffice无头方式将docx转换为pdf太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用PHPWord生成docx文件.它一直都很棒. 但是现在我还需要在pdf版本中提供其中一些文件.

I've been using PHPWord for docx files generation. And it's been working great. But now I have the need to also make available some of those files on a pdf version.

经过一些研究,我发现使用OOo的 PyODConverter .似乎是一个不错的选择,因为我不想依赖第三方Web服务.我在计算机上对其进行了尝试,并且可以正常工作,因此我也将其应用到了服务器上.花了一点时间,但我也设法在那里进行了工作.

After a few research I found PyODConverter which use OOo. Seemed quite a good option since I don't want to depend on third party web services. I tried it out on my machine and it works fined, so I've applied it on my server as well. It took a little longer but I've managed to get it working on there too.

但是有一个(不好的)问题.在服务器上,完成此过程大约需要21秒钟,而在我的计算机上,此过程不会超过2秒.:( 这太多的时间无法满足我的需求,因此我一直在尝试找出可能导致此延迟的原因. 可以通过创建套接字的无心模式启动openoffice. 因此,我一直在查看python脚本,试图找出可能导致速度变慢的指令.我将其范围缩小到了这一行:

There is however an (bad) issue. On the server this takes about 21 seconds to get it done, while on my machine it doesn't take longer than 2. :( This is way too much time for my needs so I've been trying to spot what might be causing this delay. Starting openoffice in healess mode with socket creation is okay. So I've been looking at the python script trying to find out which instruction might be causing to slow down. I've narrowed it down to this line:

context = resolver.resolve("uno:socket,host=127.0.0.1,port=8100;urp;StarOffice.ComponentContext")

此操作大约需要20秒钟才能执行. 插入代码:

This is the action that's taking about 20secs to execute. The code where it is inserted:

localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
try:
    context = resolver.resolve("uno:socket,host=127.0.0.1,port=8100;urp;StarOffice.ComponentContext")
except NoConnectException:
    raise DocumentConversionException, "failed to connect to OpenOffice.org on port %s" % port
self.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)

关于什么可能导致此延迟的任何线索? 我已经排除了我尝试转换的文档,因为此操作在此之前发生. 'uno'可能有问题吗?还是另一个缺少的库,可能会在resolve()操作期间导致无用的测试?

Any clues on what might be causing this delay? I've ruled out the document that I'm trying to convert since this operations occur before that. Could it be a problem with 'uno'? Or maybe another missing library that might be causing useless testing on during the resolve() operation?

任何想法都欢迎. :)

Any ideas are welcome. :)

最诚挚的问候,焦躁不安

Best regards, Restless

推荐答案

我设法通过使用管道而不是套接字进行连接来消除延迟.

I manage to eliminate the delay by using pipes instead of sockets for the connection.

context = resolver.resolve("uno:pipe,name=myuser_OOffice;urp;StarOffice.ComponentContext")

尽管如此,我仍然有一个问题...执行python脚本的用户必须与启动OOo的用户相同才能使一切正常运行.通常这不是什么大问题,但是我正在尝试从Web应用程序执行python,但我仍然没有设法使其正常工作. 我正在尝试这样的事情:

I still have one problem though... the user executing the python script must be the same that starts OOo for everything to work okay. Usually it would not be much of an issue, but I'm trying to execute python from my web application and I still didn't manage to get it working. I'm trying with something like this:

exec('sudo -u#1000 -s python path/to/DocumentConverter.py filename.docx filename.pdf');

我对此一无所获..我不明白为什么.也许运行exec()的用户(www-data)没有执行sudo的权限?

I'm getting nothing from this.. and I don't get why. Maybe the user (www-data) running exec() does not have permission to execute sudo??

这篇关于使用openoffice无头方式将docx转换为pdf太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆