Do Odt to PDF Conversion automatically using python or in other ways?

I want to convert an odt file to a pdf file preferrably using python and it’s libraries.

however, my odt file, besides normal text in different sizes, also has an image with my signature in it.
from what I have tested using libraries, either formating, font sizes, etc. get lsot.
or the generated pdf is jsut downright missing the image with my signature.
or things arent in the places like in the pdf.

I also thought about using weeks to manually learn the oodt format and the pdf format and do the conversion from the very scratch. but no way will I be able to manage that.

the libraries I tested havent worked out for me.
I also tried command line commands, like the “soffice …” syntax and the libreoffice version, but they at least fail when it comes to specify the output file path.
either no pdf is created, it’s created wrongly or in the wrong place, often also with some “output folder path doesnt exist” error (which is nonsense)

I jsut fail hard.

Anyone got a good recommendation for me?

But please NO API usage, I really dont want to be dependent both on the mercy of soem third party and also having to hae internet.
wanna be able to just do it on my computer directly, no senting data elsewhere.

if you get an error that “output folder doesn’t exist”, then you probably specified incorrect output folder. Perhaps you are using incorrect case somewhere, didn’t put path with spaces in quotes or used root path instead of relative local path. I am constantly using soffice to convert documents to pdf and it always works fine.

Also, which libraries have you tried? Have you tried unoserver from pip?

can you tell me an example command for the sofiice command?

like, that it should take the file.odt fil in the current folder (the one where the cmd is run and where all the stuff is) and create the -pdf file in the same folder.

the simplest one would be

soffice --headless --convert-to pdf file_name

if executed in the directory where the file is, will create a pdf with the same name in the same directory. If executed from a different directory, you will need to provide a correct path to the file and the new pdf will be created from “current working” directory. The exact way to properly write a path will slightly vary depending on what OS you are running. I recommend trying it first in the same directory as the file for simplcity.

soffice --headless --convert-to pdf file_name --outdir output_directory

will output file in the output directory you specify. You cannot directly rename a file, it will always generate pdf with the same name as the original.

hm, if I use the command as it is , it tells me that soffice is unknown command.
if i use the full path to the soffice.exe file, there’s a popup from openoffice itself that tells me that
output_pfad/pdf doesnt exist

i use openoffice 4.1.14 by the way

i have changed th command using quotes everywhere:

“C:\Program Files (x86)\OpenOffice 4\program\soffice.exe” --headless --convert-to “pdf” “Anschreiben.odt”

no console runs without issue, also no openoffice error popup anymore. but ntohing changes. no new pdf file or anything. so either nothing happens.
or there is an error that I dont get any report about :-/

new development:
seems there wereerror windows.
but since I have many things open on my computer and the damn error windows arent broguth to focus upon appearing, I ltierally have to minimize everythign else before as the last thing the error windows are there.

Error is still “outputpath\pdf doesnt exist”, so same as before :frowning:

FYI OpenOffice is an outdated software that hasn’t been developed for about 10 or 15 years now. You should use LibreOffice instead. It probably have a completely different API from soffice which is currently deployed in LibreOffice and that’s why you are having issues.

also, if you are running soffice and it tells you “can’t find it”, then you need to add it to your PATH in system settings.

Okay, mit libreoffice installiert und einer .bat Datei mit dem “Code”:

@echo off
cd /d %~dp0
soffice “c:/Program Files/LibreOffice/program/soffice.exe” --convert-to pdf *.odt

hat es nun funktioniert.

Jetzt muss ich mich halt erst mal in libreoffice einarbeiten, gerade auch wie ich von einer ods datei zur anderen formatierungen und co (aber OHNE zelleninhalte zu ändern) rüberkopieren kann und anderer kleinkram den ich sosnt in openoffice gemacht hatte bisher.
Und auch gucken, wie ich das Ganze in mein python skript einbinde, also an einem punkt in meinem python script jene .bat datei ausgeführt wird und pythone rst weriterarbeitet wenn die bat datei fertig ist

em… LibreOffice sollte alles unterstützen, was OpenOffice kann, Sie sollten also keine großen Probleme damit haben

Konnte mir nun mit einer bat Datei und 2 Python Dateien eine .exe generieren die genau die ganzen Sachen tut, die ich machen wollte :slight_smile:
Endlich muss ich nur noch die exe in einen ordner reinkopieren und ausführen und der Rest passiert von selbst :slight_smile: