Forum Discussion
What is the right way to convert Word to PDF in bulk on a PC or Mac?
NaryshkinPowershell + Microsoft Office app. The two combination can help you bulk convert Word to PDF on any Windows PC, including Windows 11, Windows 10 and Windows 7.This approach automates the conversion process without manually opening each document. First, Microsoft Office should be installed on your computer, as the script will utilize Word's COM objects to perform the conversion.
Open Notepad and paste the following PowerShell script. This script will convert all .docx files in a specified folder to .pdf:
$word = New-Object -ComObject Word.Application
$word.Visible = $false
$folderPath = "C:\Path\To\Your\Word\Files"
$outputFolderPath = "C:\Path\To\Save\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.Close()
}
$word.Quit()
The script loops through each .docx file in the designated input folder, converts it to PDF, and saves it in the output folder. The script ensures that the Word application is closed after the conversion to prevent any resource leaks. Save this script with a .ps1 extension, for example, ConvertWordToPDF.ps1.
Run the PowerShell script from the Command Prompt by typing the following command and pressing Enter:
powershell -ExecutionPolicy Bypass -File "C:\Path\To\ConvertWordToPDF.ps1"
This method provides a straightforward way to batch convert Word documents to PDF using command-line tools on Windows 11.
- paulmorrissSep 18, 2024Copper Contributor
Cordadio Thanks for that script. It's been really useful. I got a syntax error running it so I changed the SaveAs line to:
$doc.SaveAs([String] $outputPath, [ref] 17) # 17 corresponds to the wdFormatPDF format- madremixerNov 10, 2024Copper Contributor
THANK YOU THANK YOU THANK YOU THANK YOU !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- jdballouAug 20, 2024Copper ContributorI'm having a problem with this I think because I have a space in my path. I'm getting a parse error.