Apple - Command line tool to convert DOC and DOCX files to PDF

In Office 2016 the Automator approach will run into issues due to security sandboxing. (The symptom: Word stays open, and you get an "Error while printing" dialog.)

A workaround is to install LibreOffice, which can be used to convert files from the command line. On MacOS, the command is:

/Applications/LibreOffice.app/Contents/MacOS/soffice \
  --headless \
  --convert-to pdf \
  myfile.docx

The PDF will only be as good as LibreOffice's conversion from MS Office, of course, but it's adequate for many purposes.

Another approach, if you really don't care about formatting, is to use pandoc and LaTeX:

pandoc -t latex myfile.docx -o myfile.pdf

You'll need to install pandoc and LaTeX as described in this answer, though, and your PDF will come out looking like a LaTex document -- basic formatting, headers, lists, etc. will generally be preserved, but things like fonts and margins won't.


You can use the docx2pdf command line tool to bulk convert docx to pdf. It uses Microsoft Word to directly convert to pdf so you will need to have it installed. One macOS, it uses JXA (AppleScript for JavaScript) to talk to Word and on windows it uses win32com.

pip install docx2pdf

# single file
docx2pdf myfile.docx

# entire folder
docx2pdf myfolder/

Disclaimer: I wrote docx2pdf after getting frustrated at the lack of cross-platform tools to convert docx to pdf directly using Microsoft Word as I needed a perfect replica with zero formatting issues. https://github.com/AlJohri/docx2pdf