How can I convert an OpenOffice document to PDF from the Linux command line?

Solution 1:

I think the most straightforward way would be to setup a pdf printer on your box and then just:

ooffice -pt pdfprinter studentwhodoesntfollowdirectionswell.odt

Edit: Just found a post on the Ubuntu forums with someone who arrived at the same solution I suggested (with handy dandy instructions). printing to pdf from command line [SOLVED]

Edit 2: I just came across unoconv which is a python script that uses OOo's UNO bindings. So I just wanted to update this answer

Solution 2:

I do this using cups-pdf. You'll need to have OpenOffice installed, and you have to run ooffice in headless mode so the application doesn't launch a GUI.

the PDF printer is usually in the repositories, so simply sudo apt-get install cups-pdf or yum install cups-pdf.

Next you'll need to install the printer. If you wish, you can install a printer via the command line.

If you install a printer via the GUI, (on Ubuntu) it's as easy as System -> Administration -> Printing. Click the arrow and select New Printer:

alt text

Go through the wizard and make note of what you name your printer, you'll need it from the command line. As you can see, I've used cups-pdf:

alt text

Finish the wizard and you're ready to convert. Open up a terminal and run:

ooffice -headless -nologo -pt cups-pdf doc.odt

Under your home directory you'll have a PDF folder. Inside will be your converted document.

Solution 3:

$oowriter --convert-to pdf --invisible name.odt

That's all. If your CLI is graphic, you can ommit the "--invisible" option.Tested on opensuse 12.3.

Solution 4:

With the libreoffice that comes with CentOS 7 (4.1.4):

soffice --headless --convert-to pdf  file.odt 
soffice --headless --convert-to doc  file.odt 
soffice --headless --convert-to html file.odt 

soffice and libreoffice is the same binary liked to each other. oowriter is script which calls libreoffice --writer. So the above should work for all staroffice derivatives (libreoffice, openoffice).

I use it to convert hundreds of documents/day, works fine.