我需要在 Windows Server 上使用 PowerShell 将文件转换为 PDF(来自 RTF)的小脚本。我有一个使用 Word 的原型,可以在我的台式机上运行,但所涉及的服务器没有安装 Office/Word。有没有类似的方法可以调用写字板来实现相同的目标?
$documents_path = 'c:\projects\pbl\hi.rtf'
$word_app = New-Object -ComObject Word.Application
$document = $word_app.Documents.Open($documents_path)
$pdf_filename = 'c:\projects\pbl\hi.pdf'
$document.SaveAs([ref] $pdf_filename, [ref] 17)
$document.Close()
$word_app.Quit()