29

I need to batch convert a set of .doc or .docx files to .pdf in terminal, not using a GUI.

It would be helpful if I could batch-process multiple files.

I would also like to maintain as much meta-data as possible.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Ringtail
  • 16,011
  • 12
  • 60
  • 183
  • duplicate - http://superuser.com/questions/156189/how-to-convert-word-doc-to-pdf-in-linux – Panther Mar 17 '12 at 15:49
  • The best answer there is to install another application and use a "pdf printer". What is wrong using a CLI method or will I loose the meta-data – Ringtail Mar 17 '12 at 15:55
  • I didn't say there was anything wrong with oowriter, gscan2pdf or any other GUI method. I was looking for the CLI then I intend to incorporate it into the .bashrc so I could `pdf ~/some_.docx`, thats all. Thanks for the suggestion. – Ringtail Mar 17 '12 at 16:12
  • 1
    See also [this answer](http://askubuntu.com/a/104480/3940). – Takkat Mar 17 '12 at 18:47
  • @Takkat - That answer gets it into duplicate zone for me. – RobotHumans Mar 17 '12 at 19:53
  • possible duplicate of [How to convert a odt to pdf?](http://askubuntu.com/questions/60778/how-to-convert-a-odt-to-pdf) – RobotHumans Mar 17 '12 at 19:54
  • It is not really a dupe. Here we ask for batch and .doc, there for odt (not batch). The answer however would better fit here ;) – Takkat Mar 17 '12 at 20:07
  • ###### On Mac Install ```bash brew install --cask libreoffice ``` ###### Convert ```bash soffice --headless --convert-to pdf *.odt ``` – Ax_ Apr 16 '22 at 22:43

5 Answers5

40

lowriter can be used as a command line tool (lowriter is a part of LibreOffice)

lowriter --convert-to pdf *.doc
convert /home/bodhi/Documents/testdoc2.doc -> /home/bodhi/Documents/testdoc2.pdf using writer_pdf_Export
convert /home/bodhi/Documents/testdoc.doc -> /home/bodhi/Documents/testdoc.pdf using writer_pdf_Export

evince testdoc.pdf

I do not have windows, so testdoc download from here

www.mltweb.com/prof/testdoc.doc

Panther
  • 100,877
  • 19
  • 193
  • 283
  • libreofice throws errors using this method, complains of not finding /home/user/documents/test.docx blah – Ringtail Mar 20 '12 at 01:00
  • what command did you use ? Do you have a test.docx ? – Panther Mar 20 '12 at 04:06
  • lowriter --convert-to pdf /home/user/Documents/Document compatibility check.docx – Ringtail Mar 20 '12 at 04:35
  • 1
    Works perfect for me! Beware of using "space" character from command line... When you get to the space character simply press "tab" ;) – Pitto Nov 16 '12 at 13:11
  • 2
    lowriter does not convert docx files correctly. At least not always. – Sceptical Jule Dec 26 '13 at 19:56
  • @ScepticalJule- You should then file a bug report against lowriter. – Panther Dec 26 '13 at 20:24
  • 1
    When I first tried your suggested `lowriter` command on Ubuntu 12.04, it opened a splash window and froze. I killed it with C-c and tried again without a `DISPLAY` variable. This time it first printed an error about missing display, but convert the document without any problems. Is it expected behavior, that the command can only work without a `DISPLAY` environment variable? – kasperd May 30 '14 at 10:35
  • `[Java framework] Error in function createSettingsDocument (elements.cxx). javaldx failed! Warning: failed to read path from javaldx ` using https://nces.ed.gov/ccd/Data/zip/sc122a_documentation_052716.zip – isomorphismes Oct 11 '17 at 16:16
  • In general, not only just `lowriter` that mostly comes from the distro repos (used to be outdated) but also any version of LibreOffice works well now, i.e.: ``libreoffice7.2 --convert-to pdf *.doc`` – Piotr Czekalski Apr 05 '22 at 14:34
8

I use unoconv, which converts all formats supported by LibreOffice.

5

I use the following script:

for f in *.doc
do
lowriter --headless --convert-to pdf "$f"
done

--headless will prevent Libreoffice from opening 100s of files and eventually crashing if you try this with directories containing a lot of .doc files

Bruni
  • 10,180
  • 7
  • 55
  • 97
0

In my opinion, the best way is with unoconv.

First install the package:

sudo apt install unoconv

and then convert to pdf using this command:

unoconv -f pdf XXYY.docx

(Replace XXYY.docx with the name of your file.)

Zanna
  • 69,223
  • 56
  • 216
  • 327
0

You can also open that folder where you have all the .doc or .docx files and right click.Then select open terminal here. then type lowriter --convert-to pdf *.doc

Matin
  • 375
  • 1
  • 2
  • 8