Skip to content

Instantly share code, notes, and snippets.

@iknowkungfoo
Last active July 9, 2025 18:46
Show Gist options
  • Select an option

  • Save iknowkungfoo/b3e40905996dec5ddba9bb5c1a86b09e to your computer and use it in GitHub Desktop.

Select an option

Save iknowkungfoo/b3e40905996dec5ddba9bb5c1a86b09e to your computer and use it in GitHub Desktop.
This is a Windows PowerShell script for to convert MS Word documents to PDF files. You must have MS Word installed to run this script.
## Source: https://techcommunity.microsoft.com/discussions/word/what-is-the-right-way-to-convert-word-to-pdf-in-bulk-on-a-pc-or-mac/4187546/replies/4187555
## Run the script:
## powershell -ExecutionPolicy Bypass -File "C:\Path\To\ConvertWordToPDF.ps1"
##
$word = New-Object -ComObject Word.Application
$word.Visible = $false
$folderPath = "C:\Path\To\Docs"
$outputFolderPath = "C:\Path\To\PDFs"
$files = Get-ChildItem -Path $folderPath -Filter *.docx
foreach ($file in $files) {
$doc = $word.Documents.Open($file.FullName)
$pdfFilename = [System.IO.Path]::ChangeExtension($file.Name, ".pdf")
$outputPath = Join-Path -Path $outputFolderPath -ChildPath $pdfFilename
#$doc.SaveAs([ref] $outputPath, [ref] 17) # 17 corresponds to the wdFormatPDF format
$doc.SaveAs([String] $outputPath, [ref] 17) # 17 corresponds to the wdFormatPDF format
$doc.Close()
}
$word.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment