Skip to content

Bulk Convert Word Documents to PDF on Windows (Batch Script)

How to Bulk convert Word document to PDF file

Batch conversion with Word automation requires desktop Microsoft Word on Windows, Windows Script Host, and permission to run scripts. Back up documents and test a small folder before running.

Requirement

Only Ms Word. Yes, you the only requirement is MS Word with capability to save document as PDF. For Ms Word 2010 and above, this feature is already available. However, for Ms Word 2007 or lower, you need to install “Microsoft Save as PDF or XPS” plugin.

Step to Bulk Convert Word to PDF

Step 1: Organizing word files

Move all your Ms Word documents, that needs to be converted to PDF in one folder say “fldr“. You can name it anything you like.

Step 2: Code to convert Word to PDF

Open notepad/notepad++ and copy the following code and save file as “SaveAsPDF.js” in a folder say“fldr”. Note: Don’t use Ms Word to save it.

Following code converts Word document to PDF file.

var obj = new ActiveXObject("Scripting.FileSystemObject");
var docPath = WScript.Arguments(0);
docPath = obj.GetAbsolutePathName(docPath);

var pdfPath = docPath.replace(/\.doc[^.]*$/, ".pdf");
var objWord = null;

try
{
    objWord = new ActiveXObject("Word.Application");
    objWord.Visible = false;

    var objDoc = objWord.Documents.Open(docPath);

    var format = 17;
    objDoc.SaveAs(pdfPath, format);
    objDoc.Close();

    WScript.Echo("Saving '" + docPath + "' as '" + pdfPath + "'...");
}
finally
{
    if (objWord != null)
    {
        objWord.Quit();
    }
}

Step 3: Create Batch file to bulk convert Word to PDF

Open notepad or notepad++ and copy the following code. Save the file with “.bat” extension say “bulk-convert-Word2PDF.bat” in folder “fldr”.

echo off
for %%X in (*.docx) do cscript.exe //nologo SaveAsPDF.js "%%X"
for %%X in (*.doc) do cscript.exe //nologo SaveAsPDF.js "%%X"

Step 4: Running Batch file

Double click batch file “bulk-convert-Word2PDF.bat” created in above step and relax. All the word documents with .docx and .doc extension in folder “fldr” is saved to the pdf file with the same name.

Summary

Simple code shown in the blog helps automate task of converting Ms Word document into pdf files. To bulk convert Word to PDF, just double click on “bulk-convert-Word2PDF.bat” and Relax!!!

Updated practical guidance

The script uses Word COM automation (ActiveXObject), so it does not run on macOS, Word for the web or a browser. Use a trusted local directory; avoid executing downloaded scripts without inspection. Word’s PDF format constant 17 is wdFormatPDF. For unattended automation, ensure Word closes even when a document fails to open, and consider handling each file’s errors separately.

Accuracy notes and troubleshooting

The supplied batch loops over .doc and .docx files in its working directory; launching it from a different directory can process the wrong files. Add cd /d “%~dp0” after @echo off to switch to the batch file’s folder. Check whether PDFs with the same names already exist: saving may overwrite them. Complex documents, tracked changes, protected files, missing fonts and macros can affect results. Word automation is not recommended for server-side services.

Frequently asked questions

Is this method suitable for every version? Check the platform and version notes above; older desktop versions, modern Microsoft 365, macOS and web apps can behave differently. Make a copy before bulk operations.

19 thoughts on “Bulk Convert Word Documents to PDF on Windows (Batch Script)”

  1. I get this error

    C:\Users\thams\Desktop\RCID proposals>01
    ’01’ is not recognized as an internal or external command,
    operable program or batch file.

    C:\Users\thams\Desktop\RCID proposals>echo off
    ’02’ is not recognized as an internal or external command,
    operable program or batch file.
    C:\Users\thams\Desktop\RCID proposals\SaveAsPDF.js(17, 1) Microsoft JScript compilation error: Expected ‘{‘

    C:\Users\thams\Desktop\RCID proposals\SaveAsPDF.js(17, 1) Microsoft JScript compilation error: Expected ‘{‘

    C:\Users\thams\Desktop\RCID proposals\SaveAsPDF.js(17, 1) Microsoft JScript compilation error: Expected ‘{‘

    1. You have to remove the line numbers that get copied across:

      var obj = new ActiveXObject(“Scripting.FileSystemObject”);
      var docPath = WScript.Arguments(0);
      docPath = obj.GetAbsolutePathName(docPath);

      var pdfPath = docPath.replace(/\.doc[^.]*$/, “.pdf”);
      var objWord = null;

      try
      {
      objWord = new ActiveXObject(“Word.Application”);
      objWord.Visible = false;

      var objDoc = objWord.Documents.Open(docPath);

      var format = 17;
      objDoc.SaveAs(pdfPath, format);
      objDoc.Close();

      WScript.Echo(“Saving ‘” + docPath + “‘ as ‘” + pdfPath + “‘…”);
      }
      finally
      {
      if (objWord != null)
      {
      objWord.Quit();
      }
      }

      Same with the batch file.

    2. Copy and paste the text to excel first. Excel will automatically separate the line numbers from the code into two separate columns. You can then copy only the second column back into notepad without the line numbers. This is very quick and easy. Otherwise, just delete the line numbers.

  2. Add /R to the bat script to recursively process doc files in multiple folders/directories.

    echo off
    for /R %%X in (*.docx) do cscript.exe //nologo SaveAsPDF.js “%%X”
    for /R %%X in (*.doc) do cscript.exe //nologo SaveAsPDF.js “%%X”

  3. Pingback: WORD hacks – NVRMND

  4. JavaScript runtime error: Unable to get property ‘SaveAs’ of undefined or null reference

    I have installed Microsoft Office 365 Apps for Enterprise installed on my system

    Any suggestion please

Leave a Reply

Your email address will not be published. Required fields are marked *