How to convert a .docx .doc MS Word file to pdf in command line on Linux

How to convert a MS Word document file such as .docx and .doc to pdf on Linux using command line tools?

asked Feb 18, 2014 by Eric Z Ma (44,280 points)

2 Answers

Best answer

Use LibreOffice:

libreoffice --headless --convert-to pdf \
--outdir /path/to/out/dir/ /path/to/doc/docx/file
answered Feb 18, 2014 by Eric Z Ma (44,280 points)
edited Apr 26, 2014 by Eric Z Ma

While this LibreOffice answer works, the --headless option still needs as display, even though it does not use it. In otherwords, this option won't work on a truely headless server or from a cron or batch job, unless you fire up a dummy X server (eg xvfb). The LibreOffice people don't seem inclined to "fix" this:

commented Apr 23, 2017 by RobertHeller (100 points)

Hi Robert, thanks for the notes!

So in a server without a real X, it seems a command like this is needed (not yet tested):

xvfb-run libreoffice --headless --convert-to pdf \
--outdir /path/to/out/dir/ /path/to/doc/docx/file

to make it run by cron or in background.

commented Apr 23, 2017 by zma (380 points)

TextMaker, the word processor included in SoftMaker FreeOffice, has a much better compatibility with Microsoft Word compared to LibreOffice. You should download FreeOffice without charge, open your doc/docx documents faithfully with TextMaker, press the pdf button, and get a perfect pdf file.

answered Mar 5, 2014 by Hassan (140 points)

Does FreeOffice provides a command-line method to generate PDF from word .doc or .docx files? That is required to automatically generating many files.

commented Mar 5, 2014 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost