Last active
July 9, 2025 18:46
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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