word2pdf
ps1
$Word = New-Object -ComObject Word.Application
$Word.Visible = $false
#./
$path = get-location
$ext = ".pdf"
$outputFolder = ".\pdf"
#mkdir
if (-not (Test-Path $outputFolder)) {
New-Item -ItemType Directory -Force -Path $outputFolder
}
#list
$Files = Get-ChildItem -Path $path -Filter *.docx
$WordFiles = $Files.FullName
foreach ($WordFile in $WordFiles){
$doc = $word.Documents.Open($WordFile)
#word2pdf
$doc.ExportAsFixedFormat($WordFile + ".pdf", 17)
#rem
$pdffile = $WordFile + $ext
Get-ChildItem $pdffile | Foreach-Object {$newname = $_.Name -Replace ".docx",""}
Move-Item $pdffile -Destination "$path\pdf\$($newname)" -Force
}
$word.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Word) | Out-Null
[GC]::Collect()
Write-Host "finish"