How to convert a MS Word document file such as .docx and .doc to pdf on Linux using command line tools?
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:
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.
Does FreeOffice provides a command-line method to generate PDF from word .doc or .docx files? That is required to automatically generating many files.