利用powershell轉wps文件到pdf

卓能文發表於2024-07-07
$path = "D:\wps\"
$wps = New-Object -ComObject KWPS.Application

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

Get-ChildItem -Path $path -Filter *.doc? | ForEach-Object {
    $document = $wps.Documents.Open($_.FullName)
    $pdf_filename = "$($_.DirectoryName)\$($_.BaseName).pdf"
    $document.ExportAsFixedFormat([ref] $pdf_filename, [ref] $Format)
    $document.Close()
}
$wps.Quit()

相關文章