0

PyOD is a super simple python library (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. I'm using my own PC, not a 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.

I've tried running this from `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.

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.

I literally have no idea how to use python. This is for a PHP project, I'm literally only using this one small fraction of python.

Bellator
  • 352
  • 1
  • 3
  • 11
  • Try just running the command in cmd.exe exactly as you got it from github. `> "C:\Program Files\OpenOffice.org 3.1\program\python" DocumentConverter.py test.odt test.pdf` – im_baby Mar 04 '21 at 03:11
  • @im_baby Could've sworn I tried that before, guess not, but it just says "Access is Denied". Even when CMD prompt is ran as admin. – Bellator Mar 04 '21 at 03:21

1 Answers1

0

I haven't heard of PyOD, but let's assume it works like other Python-UNO scripts. First of all, be sure to start Apache OpenOffice listening on a socket, as explained on the GitHub page.

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. Then verify it.

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

If that works without errors, then exit the python prompt. Chdir to the directory where DocumentConverter.py and your files are located. Then according to the GitHub page, this should work:

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

Finally, there are easier ways of calling LibreOffice from PHP without using Python. From PHP you should be able to use a system call with the --convert-to parameter. For example, see Command `libreoffice --headless --convert-to pdf test.docx --outdir /pdf` is not working.

Jim K
  • 12,824
  • 2
  • 22
  • 51
  • I used AOO due to me being really new to all of this, and it seemed straightforward with the PyOD script. I actually did get it to work, I'll post an answer soon (I downgraded versions), but I would much prefer LibreOffice. I downloaded it and ran that command in that link from `cd /` and nothing happened, so I feel like I'm about to go down another rabbit hole. – Bellator Mar 04 '21 at 17:18