53

I have a set of files in .doc format, that need to be converted to .pdf format. I am using Ubuntu linux.

1

10 Answers 10

34

Alternative 1)

sudo apt-get install cups-pdf

Then navigate to System > Administration > Printing and create a new printer, set it as a PDF file printer, and name it as "pdf".

Then run:

oowriter -pt pdf your_word_file.doc

Now you'll find your .pdf file in ~/PDF.


Alternative 2)

sudo apt-get install wv tetex-extra ghostscript  
wvPDF test.doc test.pdf

If the tetex-extra package is not available with your distribution, try texlive-base plus texlive-latex-base:

sudo apt-get install wv texlive-base texlive-latex-base ghostscript  
wvPDF test.doc test.pdf
5
  • 1
    in oowriter -pt pdf your_word_file.doc, is the printer specified? In my computer, it will try to print to an actual printer instead of a pdf printer.
    – Tim
    Aug 8, 2011 at 18:40
  • 1
    How can I change the ~/PDF path to somewhere else ?
    – hd.
    Jan 13, 2013 at 5:05
  • 3
    OpenOffice is generally now replaced with LibreOffice, so the command is lowriter
    – flaviut
    Mar 7, 2014 at 1:05
  • 3
    for LibreOffice, the command is lowriter --convert-to pdf your_word_file.doc and the default is to output in the current directory. May 19, 2014 at 2:43
  • wvPDF not found in Lubuntu, wv version 1.2.9-4.2 is installed
    – Timo
    May 14, 2018 at 14:40
14

You can use:

oowriter -convert-to pdf:writer_pdf_Export doc_file.doc
4
  • 2
    Short and simple - however, if one is running LibreOffice (or is running OO.org and cannot find oowriter) -- the command is swriter -convert-to pdf:writer_pdf_Export x.doc.
    – new123456
    Jan 21, 2012 at 4:05
  • For Libreoffice, this works: writer -convert-to pdf:writer_pdf_Export file.docx
    – kolypto
    Jul 3, 2012 at 15:08
  • 4
    On my Ubuntu 12.04 with the default LibreOffice, I had to use lowriter instead of (oo|s| )writer. Then it worked with the same arguments as above: lowriter -convert-to pdf:writer_pdf_Export file.docx. The .pdfs are created in the current directory.
    – mivk
    Sep 6, 2012 at 23:05
  • I like this. On my 3.6.6.2 -convert-to pdf chose writer_pdf_Export as default. Also something to keep in mind - don't have any LO instances open when running this command, otherwise it will just open an empty new document in the GUI. Can this be avoided somehow?
    – lkraav
    Jun 28, 2013 at 12:24
12

Printing to PDF loses a lot of the document metadata (title, authorship, the headings tree that is used for navigation, and so on).

Install unoconv, convert with: unoconv -fpdf file1.doc file2.doc…

5
  • Thanks for the suggestion. But I think the syntax provided by you is wrong. $ unoconv myfile.doc It converts to PDF format by default and so you get myfile.pdf on executing the command.
    – nitins
    Jun 24, 2010 at 11:07
  • This is the best solution, it totally handles talking to LibreOffice for you. Oct 11, 2013 at 2:53
  • Agreed that this is the best answer. A better answer however, would be one that was as simple as this, but did not require installing the gigantic libreoffice.
    – speedplane
    Mar 22, 2016 at 8:28
  • Wow this does a lot more than that. For example you can convert html, doc, docx and more to pdf. For example to convert from html to pdf run unoconv --output output.pdf myHtmlPage.html
    – Tono Nam
    Oct 24, 2019 at 2:58
  • unoconv is deprecrated
    – afzalex
    Oct 2, 2022 at 16:37
11

If you're running X then you can do it through Open Office. Since you're about to object to doing it manually, remember there's some nice macro scripts in Open Office so you can automate it. You can do something similar with AbiWord (AbiWord --to=pdf).

If you've not got X then there is antiword, but that just extracts the text - doesn't do any formatting or graphics. There's also wvWare which I've used to bulk extract images from doc files, but I've never tried using it to convert doc files to pdfs.

Oh and .docx files may well need something different, but since they're just zipped xml files it shouldn't be too difficult to do something useful with them. For bulk extracting images you just unzip them and copy the images directory, but I've never needed to convert them in Linux.

10

If you already install LibreOffice

lowriter --headless --convert-to pdf *.doc 
7

You can also do it with AbiWord:

sudo apt-get install abiword

Then you can load .doc files in AbiWord's GUI and export to PDF, or from the commandline:

abiword --to=pdf filename.doc

2

I would try using for Linux

$ /opt/openoffice.org3.1/program/python DocumentConverter.py test.odt test.pdf

For windows:

"C:\Program Files\OpenOffice.org 3.1\program\python" DocumentConverter.py test.odt test.pdf

PyODConverter requires OpenOffice.org to be running as a service and listening on port (by default) 8100; the simplest way to start OpenOffice.org as a service is from the command line:

"C:\Program Files\OpenOffice.org 3.1\program\soffice" -accept="socket,port=8100;urp;"
0

Open Office is a good way forward, but the conversion fidelity is not always quite right.

If you are after a 100% Linux solution then that is the best way forward. However, if you don't mind a single Windows Box and write a little bit of code to interface with it from your Linux system then have a look at this post.

I wrote this post so the usual disclaimers apply.

0
  • Open -> Open Office (3.2 in my case)
  • Open Document you want to export
  • File->Export as PDF
  • Press: Export
  • Choose file name

Done and Done

1
-2
  • Install OSE VirtualBox from the software center
  • Install Windows inside VirtualBox
  • Install MS Office in the virtual Windows
  • Install dopdf in the virtual Windows
  • Set dopdf as your default printer during the installation.
  • Open the *.doc in the virtual Office and print it to the dopdf virtual printer.
  • The *.pdf file will appear in the My Documents folder of the virtual Windows
  • Send it as email attachment to wherever you need to send it.
3
  • if you use MS Office just install "Save as PDF or XPS" microsoft.com/download/en/details.aspx?id=7
    – Remus Rigo
    Jul 14, 2011 at 16:32
  • 8
    This is a lot of trouble and unnecessary licenses for simple conversions that can be done natively in linux
    – MaQleod
    Aug 5, 2011 at 0:48
  • This is a Rube Goldberg machine. Don't use this. There are so many native ways to do it.
    – Rob K
    Apr 10, 2014 at 15:54

You must log in to answer this question.