Here is a Bash script that will batch convert all specified Word .doc/x documents into PDF. As currently coded, it will read input files, and output their corresponding PDF in the same directory location. There is an option to specify the target output directory for the PDF.
If you have a programmer's editor (e.g. TextWrangler, BBEdit, Sublime Text, etc.), then just copy/paste the following code into the editor, and save as docx2pdf.sh. Otherwise, open TextEdit, and from the Format menu, select make plain text, copy/paste, and then save as the preceding filename.
This script is run from the Terminal (Launchpad : Other : Terminal). You must make the script executable before you can run it, and when you do run it
# make the script executable
$ chmod +x docx2pdf.sh
# run it without any arguments to see the usage.
$ ./docx2pdf.sh
# run the script pointed to another directory location. PDF will be written there.
$ ./docx2pdf.sh ./pfiles/*.doc*

#!/bin/bash
#
# Use LibreOffice to convert Word .doc/x files to PDF in the current,
# or relative directory location, unless --outdir option used (see below).
# Tested: macOS Sierra 10.12.3
# Version: 1.2
# VikingOSX, 2017-02-02, Apple Support Communities
#
Usage () {
printf "%s\n" "Usage"
printf "%s\n" "Process every Word .doc/x document in current folder"
printf "%s\n" "./docx2pdf.sh *.doc*"
printf "\n"
printf "%s\n" "Process selected Word documents in current folder"
printf "%s\n" "./docx2pdf.sh foo.doc bar.docx baz.doc"
exit 1
}
No_app () {
printf "%s\n" "Please install latest LibreOffice -- process terminating..."
printf "%s\n" "https://www.libreoffice.org"
exit 1
}
Report_success () {
status=$1
thefile=$2
[[ $status -eq 0 ]] || printf "%s\n" "Error: failed to process $thefile."
let filecount++
printf "%s\n" "${2/.doc*/.pdf}"
}
filecount=0
CMD="/Applications/LibreOffice.app/Contents/MacOS/soffice"
# Is LibreOffice installed? See man test.
[[ -x ${CMD} ]] || No_app
# Filenames provided to script on command-line?
[[ -n "$@" ]] || Usage
# can also direct output location with --outdir [directory name]
# PDF_Folder="~/Desktop/PDF"
# ARGS='--headless --convert-to pdf:writer_pdf_Export --outdir "${PDF_Folder}"
ARGS='--headless --convert-to pdf'
# enable Regular Expressions
shopt -s extglob
for file in "$@"
do
# ignore empty files
[[ -s "${file}" ]] || continue
case "${file}" in
# allow only these extensions. More are supported.
*.+(doc|docx|rtf|odt|wpd|cwk|txt) )
# convert to PDF (quietly)
${CMD} ${ARGS} "${file}" >& /dev/null
# if no errors, output created PDF name
Report_success $? "${file}"
continue
;;
* )
printf "%s\n" ">>> Skipping invalid file: ${file}"
continue
;;
esac
done
# disable Regular Expressions
shopt -u extglob
[[ $filecount -ge 1 ]] && printf "\n%s\n" "Files processed: $filecount files"
exit 0