Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know how to convert an ODT file (LibreOffice) to PDF?

share|improve this question
1  
Related (but not a duplicate!): How to convert pdf file to an odt file? – Eliah Kagan Jan 11 '13 at 19:15
up vote 48 down vote accepted

Just open the document with libre office and choose Export as PDF...:

enter image description here

For a command line solution there is unoconv Install NAME that converts files from the command line:

unoconv -f pdf mydocument.odt

Note: Only starting from Ubuntu 11.10 unoconv depends on Libre Office. Previous unoconv versions (from Ubuntu <= 11.04) depend on Open Office (but it will also run with Libre Office).

share|improve this answer
1  
thx for mentioning unoconv, it's great! – Boris Däppen Oct 6 '15 at 14:58

You can also use the command-line of libreoffice for your purpose. That gives you the advantage of batch conversion. But single files are also possible. This example converts all ODT files in the current directory to PDF:

libreoffice --headless --convert-to pdf *.odt

Get more information on command-line options with:

man libreoffice

(Note: Due to bug 37531, you have to close all running instances of LibreOffice before this command will work.)

share|improve this answer
    
Another argument for command line usage is that for instance in my case the gui has all of a sudden started producing flawed pdf's, but the command line still works like a charm. – Hermann Ingjaldsson Feb 27 '13 at 14:16
3  
Thi9s works, but it has a problem: if the GUI is open the command will do nothing (not even show an error). Ugly, but with this workaround you can open a new instance: --env:UserInstallation=file:///path/to/some/directory. – tokland Sep 16 '13 at 13:14
1  
@tokland: There's a bug report for that: bugs.freedesktop.org/show_bug.cgi?id=37531 – Mechanical snail Dec 2 '13 at 2:02

Nautilus Script

This script utilizes libreoffice to convert files compatible with LibreOffice to PDF.

#!/bin/bash
## PDFconvert 0.1
## by Glutanimate (http://askubuntu.com/users/81372/)
## License: GPL 3.0
## depends on python, libreoffice
## Note: if you are using a non-default LO version (e.g. because you installed it 
## from a precompiled package instead of the official repos) you might have to change
## 'libreoffice' according to the version you're using, e.g. 'libreoffice3.6'

# Get work directory
base="`python -c 'import gio,sys; print(gio.File(sys.argv[1]).get_path())' $NAUTILUS_SCRIPT_CURRENT_URI`"

#Convert documents
while [ $# -gt 0 ]; do
    document=$1
    libreoffice --headless --invisible --convert-to pdf --outdir "$base" "$document" 
    shift

done

For installation instructions see here: How can I install a Nautilus script?

share|improve this answer
2  
I just hope that such function as "lipreoffice" would be in OSX too. Sometimes, I feel my hands so short when I have to use Mac. – Masi Mar 6 '13 at 18:31

Note: I decided to delete my answer from this question and to post a modified version of it here when I realised that unoconv doesn't deal with psw files at all well, and doesn't convert them successfully to other formats. There may also be problems with docx and xlsx formats.


However, Libreoffice fully supports many file types; full documentation is available at the official site, which details the valid input and output formats.

You could use the command-line libreoffice convert utility or unoconv, which is available in the repositories. I find unoconv to be very useful, and it is probably what you want. Even though Takkat has briefly mentioned unoconv, I thought it would be useful to give some more details and a batch conversion one-liner.

Using the terminal you could cd to the directory containing your files and then batch convert all of them by running a one-liner like this:

for f in *.odt; do unoconv -f pdf "${f/%pdf/odt}"; done

(This one-liner is a modification of my translate script featured in this answer.)

If you later want to use any other file formats, just substitute the odt and pdf for any other supported input and output formats. You can find the supported formats for a file type by entering unoconv -f odt --show. To convert a single file use, for example, unoconv -f pdf myfile.odt.

Further information on and options for the program can be found by entering in terminal man unoconv or by going to the Ubuntu manpages online.

share|improve this answer

Another Nautilus Script

This very simple and lightweight Nautilus Script uses unoconv to convert selected file(s) compatible with LibreOffice to PDF format:

#!/bin/sh
#Nautilus Script to convert selected LibreOffice-compatible file(s) to PDF
#
OLDIFS=$IFS
IFS="
"
for filename in $@; do
unoconv --doctype=document --format=pdf "$filename"
done
IFS=$OLDIFS
share|improve this answer

Consider using the docspal service (http://www.docspal.com). It is free, fast and supports lots of formats. Hope, it will be useful for you.

share|improve this answer

Here are a few more details about the "non-GUI" method.

  1. You can use this method not only to convert ODT files to PDF. It will also work for MS Word DOCX files (it will work as well as LibreOffice is able to handle the particular ODT), and, in general all file types which LibreOffice can open.

  2. I do not think that there is a binary named libreoffice as one of the other answers suggested. However, there is soffice(.bin) -- the binary that can be used to start LibreOffice from the command line. It is usually located in /usr/lib/libreoffice/program/; and very often, a symlink /usr/bin/soffice points to that location.

  3. Then, in most cases the parameters --headless --convert-to pdf are not sufficient. It needs to be:

    --headless --convert-to pdf:writer_pdf_Export
    

    Be sure to follow exactly this capitalization!

  4. Next, the command will not work if there is already a LibreOffice GUI instance up and running on your system. It is caused by bug #37531, known since 2011. Add this additional parameter to your command:

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

    This will create a new, separate environment which can be used by a second, headless LO instance without interfering with a possibly running first GUI LO instance started by the same user.

  5. Also, make sure that the --outdir /pdf you specify does exist, and that you have write permission to it. Or, rather use a different output dir. Even if it is just for a first testing and debugging round:

    $ mkdir ${HOME}/lo_pdfs
    
  6. Hence:

    /path/to/soffice                                                     \
      --headless                                                         \
      "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_${USER}" \
      --convert-to pdf:writer_pdf_Export                                 \
      --outdir ${HOME}/lo_pdfs                                           \
    /path/to/test.docx
    

    This works for me on Mac OS X Yosemite 10.10.5 with LibreOffice v5.1.2.2 (using my specific path for the binary soffice which will be different on Ubuntu anyway...). It also works on Debian Jessie 8.0 (using path /usr/lib/libreoffice/program/soffice). Sorry, cannot test it on Ubuntu right now....

    If all this doesn't work, when you try to process DOCX:

  7. It may be a problem with the specific DOCX file you try the command with... So create a very simple DOCX document of your own first. Use LibreOffice itself for this. Write "Hello World!" on an otherwise empty page. Save it as DOCX.

  8. Try again. Does it work with the simple DOCX?

  9. If it again doesn't work, repeat step 7, but save as ODT this time.

  10. Repeat step 8, but make sure to reference the ODT this time.

  11. Last: Use full path to soffice, to soffice.bin and to libreoffice and run each with the -h parameter:

    $ /path/to/libreoffice -h  # if that path exists, which I doubt!
    $ /path/to/soffice -h
    $ /path/to/soffice.bin -h
    
    • Do you get an output here?
    • For which one of the three binaries/symlinks?
    • Record the outputs.
    • Tell us your outputs!!!
       

    Compare them to the command line you used:

    • Are there any changes in parameter names, capitalizations, number of dashes used, etc.??
       

    For comparison, my own (Mac OS X) output is here:

     $ /Applications/LibreOffice.app/Contents/MacOS/soffice -h 
    
     LibreOffice 5.1.2.2 d3bf12ecb743fc0d20e0be0c58ca359301eb705f
    
     Usage: soffice [options] [documents...]
    
     Options:
     --minimized    keep startup bitmap minimized.
     --invisible    no startup screen, no default document and no UI.
     --norestore    suppress restart/restore after fatal errors.
     --quickstart   starts the quickstart service
     --nologo       don't show startup screen.
     --nolockcheck  don't check for remote instances using the installation
     --nodefault    don't start with an empty document
     --headless     like invisible but no user interaction at all.
     --help/-h/-?   show this message and exit.
     --version      display the version information.
     --writer       create new text document.
     --calc         create new spreadsheet document.
     --draw         create new drawing.
     --impress      create new presentation.
     --base         create new database.
     --math         create new formula.
     --global       create new global document.
     --web          create new HTML document.
     -o             open documents regardless whether they are templates or not.
     -n             always open documents as new files (use as template).
    
     --display <display>
           Specify X-Display to use in Unix/X11 versions.
     -p <documents...>
           print the specified documents on the default printer.
     --pt <printer> <documents...>
           print the specified documents on the specified printer.
     --view <documents...>
           open the specified documents in viewer-(readonly-)mode.
     --show <presentation>
           open the specified presentation and start it immediately
     --accept=<accept-string>
           Specify an UNO connect-string to create an UNO acceptor through which
           other programs can connect to access the API
     --unaccept=<accept-string>
           Close an acceptor that was created with --accept=<accept-string>
           Use --unnaccept=all to close all open acceptors
     --infilter=<filter>[:filter_options]
           Force an input filter type if possible
           Eg. --infilter="Calc Office Open XML"
               --infilter="Text (encoded):UTF8,LF,,,"
     --convert-to output_file_extension[:output_filter_name[:output_filter_options]] [--outdir output_dir] files
           Batch convert files (implies --headless).
           If --outdir is not specified then current working dir is used as output_dir.
           Eg. --convert-to pdf *.doc
               --convert-to pdf:writer_pdf_Export --outdir /home/user *.doc
               --convert-to "html:XHTML Writer File:UTF8" *.doc
               --convert-to "txt:Text (encoded):UTF8" *.doc
     --print-to-file [-printer-name printer_name] [--outdir output_dir] files
           Batch print files to file.
           If --outdir is not specified then current working dir is used as output_dir.
           Eg. --print-to-file *.doc
               --print-to-file --printer-name nasty_lowres_printer --outdir /home/user *.doc
     --cat files
           Dump text content of the files to console
           Eg. --cat *.odt
     --pidfile=file
           Store soffice.bin pid to file.
     -env:<VAR>[=<VALUE>]
           Set a bootstrap variable.
           Eg. -env:UserInstallation=file:///tmp/test to set a non-default user profile path.
    
     Remaining arguments will be treated as filenames or URLs of documents to open.
    
  12. Add one more argument to your command line to enforce the application of an input filter when soffice opens your DOCX file:

    --infilter="Microsoft Word 2007/2010/2013 XML"
    

    or

    --infilter="Microsoft Word 2007/2010/2013 XML"
    --infilter="Microsoft Word 2007-2013 XML"
    --infilter="Microsoft Word 2007-2013 XML Template"
    --infilter="Microsoft Word 95 Template"
    --infilter="MS Word 95 Vorlage"
    --infilter="Microsoft Word 97/2000/XP Template"
    --infilter="MS Word 97 Vorlage"
    --infilter="Microsoft Word 2003 XML"
    --infilter="MS Word 2003 XML"
    --infilter="Microsoft Word 2007 XML Template"
    --infilter="MS Word 2007 XML Template"
    --infilter="Microsoft Word 6.0"
    --infilter="MS WinWord 6.0"
    --infilter="Microsoft Word 95"
    --infilter="MS Word 95"
    --infilter="Microsoft Word 97/2000/XP"
    --infilter="MS Word 97"
    --infilter="Microsoft Word 2007 XML"
    --infilter="MS Word 2007 XML"
    --infilter="Microsoft WinWord 5"
    --infilter="MS WinWord 5"
    
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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