简体   繁体   English

如何在 OpenOffice 中使用 PyOD?

[英]How to use PyOD with OpenOffice?

PyOD is a super simple python library ( https://github.com/mirkonasato/pyodconverter ). PyOD 是一个超级简单的 python 库( https://github.com/mirkonasato/pyodconverter )。

It has one command usage它有一个命令用法

> "C:\Program Files (x86)\OpenOffice 4\program\python-core-2.7.18" DocumentConverter.py test.odt test.pdf

This should convert test.odt to a pdf.这应该将test.odt转换为 pdf。 I'm using my own PC, not a VPS.我使用的是我自己的 PC,而不是 VPS。

I can't figure out how to use this command.我不知道如何使用这个命令。 I've been at this for literally 3 hours, I have no experience in python or the command line.我已经在这里工作了 3 个小时,我在 python 或命令行方面没有经验。

I've tried running this from `cmd.exe我试过从 `cmd.exe 运行它

cd /
python "C:\Program Files (x86)\OpenOffice 4\program\python-core-2.7.18" DocumentConverter.py test.odt test.pdf

But it gave me this error:但它给了我这个错误:

C:\Users\user\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe: can't find '__main__' module in 'C:\\Program Files (x86)\\OpenOffice 4\\program\\python-core-2.7.18'

And I have absolutely NO idea what it means, google was not helpful.而且我完全不知道这意味着什么,谷歌没有帮助。

I've also tried我也试过

cd Program Files (x86)\OpenOffice 4\program\python-core-2.7.18
DocumentConverter.py test.odt test.pdf

All this did was try and open the file.所有这一切都是尝试打开文件。 It asked me what I wanted to open it with, I chose Python.exe and it simply opened a python terminal then closed it immediately, and no new file was in python-core-2.7.18 so I'm assuming it didn't work.它问我想用什么打开它,我选择了 Python.exe,它只是打开了一个 python 终端然后立即关闭它, python-core-2.7.18中没有新文件,所以我假设它没有工作。

So THEN I tried opening python.exe directly from python-core-2.7.18 and running DocumentConverter.py test.odt test.pdf but it said I had invalid syntax.所以我尝试直接从python-core-2.7.18打开python.exe并运行DocumentConverter.py test.odt test.pdf但它说我的语法无效。

I literally have no idea how to use python.我真的不知道如何使用 python。 This is for a PHP project, I'm literally only using this one small fraction of python.这是针对 PHP 项目的,我实际上只使用了 python 的一小部分。

I haven't heard of PyOD, but let's assume it works like other Python-UNO scripts.我还没有听说过 PyOD,但我们假设它像其他 Python-UNO 脚本一样工作。 First of all, be sure to start Apache OpenOffice listening on a socket, as explained on the GitHub page.首先,请务必启动 Apache OpenOffice 监听套接字,如 GitHub 页面中所述。

soffice -accept=socket,host=localhost,port=2002;urp;

Next, open a command prompt and go to the directory where the UNO-enabled python executable is located.接下来,打开命令提示符和 go 到启用 UNO 的 python 可执行文件所在的目录。 Then verify it.然后验证它。

cd C:\Program Files (x86)\OpenOffice 4\program
python
>>> import uno

If that works without errors, then exit the python prompt.如果没有错误,则退出 python 提示符。 Chdir to the directory where DocumentConverter.py and your files are located. Chdir 到DocumentConverter.py和您的文件所在的目录。 Then according to the GitHub page, this should work:然后根据 GitHub 页面,这应该可以工作:

"C:\Program Files (x86)\OpenOffice 4\program\python" DocumentConverter.py test.odt test.pdf

Another question: Did you choose AOO instead of LibreOffice for a particular reason?另一个问题:您选择 AOO 而不是 LibreOffice 是否出于某种特殊原因? If you are not familiar with the suite, you will probably want to try LibreOffice first, as that has been developed more and will probably be easier to get working.如果您不熟悉该套件,您可能想先尝试 LibreOffice,因为它已经开发得更多并且可能更容易上手。

Finally, there are easier ways of calling LibreOffice from PHP without using Python.最后,还有更简单的方法可以从 PHP 调用 LibreOffice,而无需使用 Python。 From PHP you should be able to use a system call with the --convert-to parameter.从 PHP 开始,您应该能够使用带有--convert-to参数的系统调用。 For example, see Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working .例如,请参阅命令 `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working

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

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