Issue When Calling Libreoffice For Pdf Generation From Python Of Docx With Charts
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"