Docx to pdf using openoffice headless way too slow

你说的曾经没有我的故事 提交于 2019-12-05 05:38:40

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")

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');

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??

Perhaps the name resolver on the server doesn't know localhost (which would be very odd, but 20 seconds does sound like a DNS timeout). You could try replacing it with 127.0.0.1.

Alternatively, perhaps it's doing the lookup fine, getting both IPv6 and IPv4 addresses back for localhost, trying to make the connection via IPv6 and failing (i.e. the component may not support IPv6, or doesn't bind to that interface by default) and only then falling back to IPv4. In that case, the remedy would be the same: replace localhost with 127.0.0.1.

Its a pity that openoffice is so heavy. I was also considering it, but then I found lighter solution that is abiword.

I had to generate the previews of 4 first pages from uploaded document. This is what I did:

abiword document.doc --to=ps --exp-props="pages:1-4"
gs -q -dNOPAUSE -dBATCH -dTextAlphaBits=4  -dGraphicsAlphaBits=4 -r72 -sDEVICE=pnggray -sOutputFile=preview%d.png document.ps

So you may get the recent abiword and try something like this:

abiword document.docx --to=pdf
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!