How to batch convert DOC to PDF?

Dear list members, is there a way now under Mac OS X 10.12.1 to batch convert DOC or DOCX files to PDF? As I need to do this kind of conversion on a regular basis for several files, it is very time consuming to do it in Word for each file separately. I found some similar threads here in the forum, but the proposed solutions are outdated and so do not work anymore. Thank you!

iMac (Retina 5K, 27-inch, Late 2015), OS X El Capitan (10.11.4)

Posted on Feb 1, 2017 3:29 AM

Reply
23 replies

Feb 1, 2017 8:29 AM in response to morceg@o

If you want features to be seen in the PDF that only Word on Windows can generate, but those features are not yet implemented on the Mac, then it would suggest that you use the Windows version of Word to achieve your batch PDF output requirements.


You can experiment with various .doc/x to PDF conversion solutions on the Mac to arrive at the conclusion of the first paragraph.


The free LibreOffice has a command-line invocation that can readily convert .doc/x to PDF, and lends itself to batch processing. But LibreOffice, regardless of Mac, or Windows version, still is not a Windows MS Word, and the functionality that you want to see in the final PDF may not be included either.


Compare this PDF output to what you get from Word on Windows when saving the same document to PDF. The following will produce the a.pdf document in the same location from which it was run.


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

Feb 2, 2017 11:31 AM in response to morceg@o

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*

User uploaded file

#!/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

Feb 1, 2017 10:51 AM in response to komplikated1

No version of Pages is a Word clone, and on opening a Word document, a translation into the internal Pages document format occurs. There is no assurance by Apple that this translation process will retain the original Word document content, or even layout accuracy. At no time, are you editing the original native Word document in Pages.


The OP stated that some of the features that were needed in the final PDF were found only with the Windows Word application when saved to PDF, and not implemented on Word for Mac versions. Under those conditions, and Apple's lethargic support of current Word features in Pages, the latter would be a poor application choice for the OP to use in conversion of .doc/x to PDF.

Feb 2, 2017 1:06 AM in response to morceg@o

morceg@o wrote:


Thank you, Luis. Do you have an script for that?

Sorry, I tried a quick script but I am not familiar enough with word, and only marginally able at applescript, and could not make it work. I would try a little more, but I can't afford the time right now.

In the present circumstances, I think that you should try VikingOSX's advice and gibe LibreOffice a shot.

Feb 2, 2017 10:06 AM in response to VikingOSX

Great script.


Allow me to make a small suggestion: this may be easier to set up and use as an automator service.

I did not have the chance to test because I don't have LibreOffice installed at the moment, but I don't see why this would not work:


1) Open Automator

2) Create a new Service

3) Change "Service Receives" to "Files or folders" and In to "Finder"

4) From Utilities, drag "Run Shell Script" to the right. Copy and paste the script into it.

5) Change the the shell to /bin/bash (if not already), and change "Pass input" to "as arguments"

6) Save this with a meaningful name (like "Convert to PDF")


To use, just select a bunch of word files in Finder, control-click and choose Services->Convert to PDF

Feb 2, 2017 11:02 AM in response to Luis Sequeira1

Looks like a project for you. 😉


I wrote a quick Automator application that used the Ask for Finder Items (files, multiple selection), and Filter Finder Items on any extension .doc and .docx. I placed the unmodified script as posted into a Run Shell Script action (without the boilerplate for loop) and it takes its arguments from the command-line. It dutifully writes the PDF into the home folder — when the files came from the Desktop. You may have to hardcode a folder location for the --outdir argument in the script if you want to control the written PDF destination.


What users will miss with an Automator solution is the visual progress of output PDF names, and a final PDF count when done (without an added osascript display dialog).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to batch convert DOC to PDF?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.