I want to use LibreOffice to convert a file to pdf. I can do it alright from the command line, but I haven't been able to make the call from python. I'm on a Mac and there are two steps:
/Applications/LibreOffice.app/Contents/MacOS
)./soffice --headless --convert-to pdf input_folder--outdir output_folder
I tried
subprocess.run(["cd", libreoffice_path])
subprocess.run(["./","soffice","--headless","--convert-to", "pdf", input_folder, "--outdir", output_folder])
but I'm getting a Permission denied: './'
error.
I thought it was an access error and made soffice executable (although I suspect it already was) by using chmod +x
from the command line. Still no luck.
What am I missing?
You split the first argument into two. Try running:
subprocess.run(["./soffice", "--headless", "--convert-to", "pdf", input_folder, "--outdir", output_folder])
also, a better way to change the working directory is to use os.chdir
:
import os
os.chdir(libreoffice_path)