我正在尝试使用 PowerShell 将 Word Docx 批量转换为 PDF - 使用此站点上的脚本:http: //blogs.technet.com/b/heyscriptingguy/archive/2013/03/24/weekend-scripter -convert-word-documents-to-pdf-files-with-powershell.aspx
# Acquire a list of DOCX files in a folder
$Files=GET-CHILDITEM "C:\docx2pdf\*.DOCX"
$Word=NEW-OBJECT –COMOBJECT WORD.APPLICATION
Foreach ($File in $Files) {
# open a Word document, filename from the directory
$Doc=$Word.Documents.Open($File.fullname)
# Swap out DOCX with PDF in the Filename
$Name=($Doc.Fullname).replace("docx","pdf")
# Save this File as a PDF in Word 2010/2013
$Doc.saveas([ref] $Name, [ref] 17)
$Doc.close()
}
而且我不断收到此错误,无法弄清楚原因:
PS C:\docx2pdf> .\docx2pdf.ps1
Exception calling "SaveAs" with "16" argument(s): "Command failed"
At C:\docx2pdf\docx2pdf.ps1:13 char:13
+ $Doc.saveas <<<< ([ref] $Name, [ref] 17)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
有任何想法吗?
另外 - 我需要如何更改它以转换 doc(不是 docX)文件,以及使用本地文件(与脚本位置位于同一位置的文件)?
抱歉 - 从未编写过 PowerShell 脚本...