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

4

4

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?

Norman Ramsey

Posted 2010-01-05T19:16:56.663

Reputation: 2 613

Answers

6

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

Tyler

Posted 2010-01-05T19:16:56.663

Reputation: 4 203

2unoconf file.odt file.pdf is the better way. You'll get the yummy metadata that a pdf printer doesn't include. – Tobu – 2010-06-11T14:37:41.533

Gross, but it should work, thanks. Link to Ubuntu thread with details of the filename gets the check mark. – Norman Ramsey – 2010-01-05T20:29:35.520

1

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

olb

Posted 2010-01-05T19:16:56.663

Reputation: 11

1Can you expand on your answer with more detail? – Sickest – 2014-02-26T19:12:32.937

1

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.

sivann

Posted 2010-01-05T19:16:56.663

Reputation: 141

1

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.

John T

Posted 2010-01-05T19:16:56.663

Reputation: 149 037

+1 thanks. Your last name isn't "Skeet"? – Norman Ramsey – 2010-01-05T20:30:33.507

Nope, different people :) – John T – 2010-01-05T20:40:19.447