Skip to content

Instantly share code, notes, and snippets.

@alexisnomine
Created March 7, 2014 09:58
Show Gist options
  • Save alexisnomine/9408777 to your computer and use it in GitHub Desktop.
Save alexisnomine/9408777 to your computer and use it in GitHub Desktop.
Batch convert docx to pdf with powershell
Param(
[Parameter(Mandatory=$True)]
[string]$FilePath
)
$Files = Get-ChildItem "$FilePath\*.docx"
$Word = New-Object -ComObject Word.Application
Foreach ($File in $Files) {
# open a Word document, filename from the directory
$Doc = $Word.Documents.Open($File.FullName)
# Swap out DOCX with PDF in the Filename
$Name=($Doc.FullName).Replace("docx","pdf")
# Save this File as a PDF in Word 2010/2013
$Doc.SaveAs([ref] $Name, [ref] 17)
$Doc.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment