利用powershell转word文档到pdf

$path = "D:\word\"
$word_app = New-Object -ComObject Word.Application

# $Format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatXMLDocument
$Format = [Microsoft.Office.Interop.Word.WdSaveFormat]::wdFormatPDF

Get-ChildItem -Path $path -Filter *.doc? | ForEach-Object {
    $document = $word_app.Documents.Open($_.FullName)
    $pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
    $document.SaveAs([ref] $pdf_filename, [ref] $Format)
    $document.Close()
}
$word_app.Quit()
posted @ 2024-07-07 00:14  卓能文  阅读(97)  评论(0)    收藏  举报