I have students who, when asked for PDF, sometimes hand me an OpenOffice document or spreadsheet. file(1) can identify these documents, but I've been unable to discover how to convert them to PDF using the command line. (The man page for ooffice(1) lists an option to print a document but not to convert to PDF.) Google is unhelpful, except for giving me the uneasy feeling that this can't be done without a nifty script in a language I don't know against an API whose documentation I can't find.

Can anyone help me solve the problem of converting an OpenDocument to PDF using only the Unix command line?


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

  • Gross, but it should work, thanks. Link to Ubuntu thread with details of the filename gets the check mark. Jan 5 '10 at 20:29
  • 2
    unoconf file.odt file.pdf is the better way. You'll get the yummy metadata that a pdf printer doesn't include.
    – Tobu
    Jun 11 '10 at 14:37

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.

  • Nope, different people :)
    – John T
    Jan 5 '10 at 20:40

$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.


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.

  • I tried it unfortunately it hangs with an open error dialogs waiting for user when something goes wrong, like max. columns hit. Headless is not headless if the user has office already open. So in a background program call it can be very bad.
    – Lothar
    Mar 6 '20 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.