I modified what someone else had on this forum, based on a successful use of powershell Excel to pdf with no success. Any ideas on my failing in the following code? My goal is to be able to convert an entire folder of doc and docx documents to pdf without opening the native applications. Thanks in advance:
# Acquire a list of DOC files in a folder
$Word = New-Object -ComObject word.application
$path = "c:\Users\Desktop\Test"
$formats = "Microsoft.Office.Interop.Word.WdFixedFormatType" -as [type]
$Word.visible = $false
$fileTypes = "*.docx","*doc"
$Files = GET-CHILDITEM $path -include $fileTypes
Foreach ($File in $Files) {
$filepath = Join-Path -path $path -childpath ($File.basename +".pdf")
$Doc = $Word.open($File.fullname, 3)
$Doc.Saved= $true
"Converting $File to pdf ... $destPath"
# Save this File as a PDF in Word 2010/2013
$Doc.ExportAsFixedFormat($formats::wdTypePDF, $path)
$Doc.FullName -replace '\.doc?$', '.pdf'
$Doc.Close()
}
$Word.Quit()