1

I have many .odt files in my Windows system. I would like to convert these files to PDF. I tried that in command line

soffice.bin --headless -convert-to pdf:"writer_pdf_Export" c:\MyOdtFile.odt

But, It does not work. This method can only open file, does not convert! How can I do this?

esquare
  • 3,947
  • 10
  • 34
  • 37
  • Would it be an option to use libreoffice instead of OpenOffice? LO supports command-line pdf conversion out of the box. – tohuwawohu Jun 30 '14 at 16:15
  • see also http://stackoverflow.com/q/355447/342546 – tohuwawohu Jun 30 '14 at 16:17
  • Yes, I can use LO instead of Openoffice. In fact, I installed it portable version and normal version after your commet. But It does not work. I tried using that command : soffice.bin --headless -conver-to:pdf:"writer_pdf_Export" c:\Myfile.odt – esquare Jul 01 '14 at 06:25

2 Answers2

3

With LibreOffice, the following command should work:

soffice.exe --headless -convert-to pdf --outdir <output directory> <file1.odt> <file2.odt>

When converting to pdf, -convert-to pdf is sufficient. The --outdir parameter is optional; if you don't use it, the PDF will be created in the current working directory. Using soffice.bin didn't work for me (missing sal3.dll), but soffice.exe works (LibreOffice 4.2.4.2, Win 7). If soffice.exe isn't in your path, you would have to set the PATH explicitly or add the complete path to the command above:

' "C:\Program Files (x86)\LibreOffice 4\program\soffice.exe" --headless -convert-to pdf --outdir C:\temp test1.odt`

Make sure that LO isn't running when issuing the convert command - otherwise the conversion will fail without an error message.

tohuwawohu
  • 13,268
  • 4
  • 42
  • 61
3

To add to @tohuwawohu's answer... he wrote:

Make sure that LO isn't running when issuing the convert command - otherwise the conversion will fail without an error message.

This can be eliminated by adding another parameter to the command line:

-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}"

This creates a new environment for ${USER}'s headless instance of LibreOffice, should he have already a not-headless, GUI one running.

This way, the headless instance will not conflict with the already running instance.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345