Uncategorized

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


Hello,
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.
alternatively

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:



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *