How To Convert All Word Documents in A Folder to PDF

0

A colleague came to me the other day asking if there is an easy way to convert all Word documents in a folder to PDF. I couldn’t think of anything on top of my mind at first. Since there are tons of documents in that folder waiting to be converted, I took the chance and give it a try using PowerShell.

image 9 600x269 - How To Convert All Word Documents in A Folder to PDF

MS Office has a Save-to-PDF feature out of the box since Office 2010 so let’s use that feature and see how the outcome is.

First of all, call up a new COM object for Word application. And then get all the Word files in a folder, open each one of them and save as a PDF file using [ref] 17.

Putting together,

$documents_path = 'path'

$word_app = New-Object -ComObject Word.Application

# This filter will find .doc as well as .docx documents
Get-ChildItem -Path $documents_path -Filter *.doc? | ForEach-Object {

    $document = $word_app.Documents.Open($_.FullName)
    $pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
    $document.SaveAs([ref] $pdf_filename, [ref] 17)
    $document.Close()
}

$word_app.Quit()

Given the folder that has all your PDF Word files in the first line and it works like a charm.

And once again, in order to this works you will need MS Office 2010 or above on your computer. A full version of Adobe like Adobe Standard is not required.

Credit goes to the awesome StackOverflow

Was this article Helpful?

Thank you for the feedback!

LEAVE A REPLY

Please enter your comment!
Please enter your name here