Skip to content Skip to sidebar Skip to footer

Issue When Calling Libreoffice For Pdf Generation From Python Of Docx With Charts

using debian 9.5, python 3.5, libreoffice 5.2, x86_64 arch. I have a word file (docx) of 22 pages, which contains several charts. When run from terminal using bash, the following c

Solution 1:

I found a solution, although it is not clear to me the technical reason:

this WORKS (complete pdf generation using libreoffice of docx file with charts):

PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-10-oracle/bin:/usr/lib/jvm/java-10-oracle/db/bin /usr/bin/libreoffice -env:UserInstallation=file:///tmp/docx5/ --headless --convert-to pdf --outdir /tmp/docx5/ /tmp/docx5/output.docx

this DOES NOT WORK (partial pdf generation using libreoffice of docx file with charts):

PATH=/home/marco/venv/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-10-oracle/bin:/usr/lib/jvm/java-10-oracle/db/bin /usr/bin/libreoffice -env:UserInstallation=file:///tmp/docx5/ --headless --convert-to pdf --outdir /tmp/docx5/ /tmp/docx5/output.docx

It seems that python virtualenv causes some sort of conflict with libreoffice. I used strace but found nothing useful.

So the solution for my case is to remove the virtualenv path from PATH environment variable when calling libreoffice from python, and this can be achieved by deactivating virtualenv:

marco@pc:~$ source venv/bin/activate
...
(venv) marco@pc:~$ deactivate && /usr/bin/libreoffice -env:UserInstallation=file:///tmp/docx5/ --headless --convert-to pdf --outdir /tmp/docx5/ /tmp/docx5/output.docx

Solution 2:

Adding this for anybody else who runs into this issue, the reason you get the error message is because the path variable used by subprocess and passed to libreoffice is not sufficient to find the jre. I ran into this same issue, and changed it to the following which seems to fix it.

subprocess.run(cmd,env={'HOME':'/home/username'})

Post a Comment for "Issue When Calling Libreoffice For Pdf Generation From Python Of Docx With Charts"