PickupBrain

Bulk convert WORD to PDF for free

Converting a Word document to PDF file is simple and easy. Just open Word document in Ms Word and save as PDF. But what if you have tons of Word files to convert into PDF? Opening each file manually and saving it to PDF will take ages. But using the following trick, you can bulk convert Word to PDF in just one click. And that too using no external tool. You just need Ms Word.

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

Related Posts

7 thoughts on “Bulk convert WORD to PDF for free

  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. Hi, Thanks, I have some errors when I want to add other extensions as xls and ppt. Can you please help? Thanks

Leave a Reply