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?
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
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 :-/
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
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”:
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
Konnte mir nun mit einer bat Datei und 2 Python Dateien eine .exe generieren die genau die ganzen Sachen tut, die ich machen wollte
Endlich muss ich nur noch die exe in einen ordner reinkopieren und ausführen und der Rest passiert von selbst