Created
March 7, 2014 09:58
-
-
Save alexisnomine/9408777 to your computer and use it in GitHub Desktop.
Batch convert docx to pdf with powershell
This file contains 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
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