Bash LibreOffice – How to Convert LibreOffice ODT to PDF in Bash

libreofficepdf

I am using libreoffice under CentOS 6. I can convert ODT files to PDF with:

libreoffice --headless --convert-to pdf *.odt
but the problem is that it only works when no document is open in libreoffice.

When I specify --env:UserInstallation=file:///path/to/some/directory
as suggested in one of the comments of this question , it doesn't help.

What am I doing wrong? It is a nuisance to close all libreoffice instances before running the before command.

Best Answer

That is unlikely going to work, as the suggestion in the comment is both incomplete (you cannot just specify some directory) and incorrect (--env:... should be -env:... Here is what I recommend you do:

  1. Stop all instances of libreoffice
  2. Start libreoffice from the commandline without specifying --headless:

    libreoffice -env:UserInstallation=file:///home/username/.config/libreoffice-alt
    

    you should replace /home/username with your home directory (and adjust .config if you don't have that on your CentOS, I did this on Ubuntu and Linux Mint). The above will create a new configuration directory for the alternate libreoffice in your .config directory, without which you would get some error about java not being found.

  3. Exit that instance of libreoffice
  4. That directory /home/username/.config/libreoffice-alt should now have been created for you.

Now start another libreoffice from the command-line (doing so allows you to see some useful messages if things go wrong when starting the second instance), without the -env:..., and while that is still running start the conversion using:

libreoffice -env:UserInstallation=file:///home/username/.config/libreoffice-alt --headless --convert-to pdf *.odt
Related Question