How to convert a .docx .doc MS Word file to pdf in command line on Linux
Posted on In QAHow to convert a MS Word document file such as .docx and .doc to pdf on Linux using command line tools?
Use LibreOffice:
libreoffice --headless --convert-to pdf
--outdir /path/to/out/dir/ /path/to/doc/docx/file
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:
https://bugs.documentfoundation.org/show_bug.cgi?id=107151
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.
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.
freeoffice.com
Does FreeOffice provides a command-line method to generate PDF from word .doc or .docx files? That is required to automatically generating many files.