3
有人可以请指导我该怎么解决代码?我需要将PowerPoint文件转换为PDF文件。将ppt转换为PDF时出错
代码:
#Convert Powerpoint formats to pdf
Param(
[string]$inputPath,
[string]$outputPath
)
Add-Type -AssemblyName Office
Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint
$ppFormatPDF = 32
$ppQualityStandard = 0
$pp = New-Object -ComObject PowerPoint.Application
# TODO: Why this property does not work
#$pp.visible = [Microsoft.Office.Core.MsoTriState]::msoFalse
$ppt = $pp.Presentations.Open($inputPath)
$ppt.SaveAs($outputPath, $ppFormatPDF) # 32 is for PDF
$ppt.Close()
$pp.Quit()
$pp = $null
[gc]::Collect()
[gc]::WaitForPendingFinalizers()
错误:
Exception calling "SaveAs" with "2" argument(s): "Presentation.SaveAs :
PowerPoint can't save ^0 to ^1."
At D:\AllAquent\Rambo\Digo\war\WEB-INF\classes\resources\pptToPdf.ps1:17 char:12
+ $ppt.SaveAs <<<< ($outputPath, $opt) # 32 is for PDF
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
您的错误消息与您的代码不符。 '$ opt'的值是否真的是32?您的PowerPoint版本是否实际支持以PDF格式保存? –