Yesterday I was trying to batch convert a group of PPTs into PDFs for a friend, and I decided to have a look at PowerShell, since it's been sitting on my HD for a while.
Here's the code I've come up with.
$p = new-object -comobject powerpoint.application
# I actually don't know why I have to set the window to visible,
# but it doesn't work otherwise, anyway, it's not the real problem I have
$p.visible = 1
$f = $p.presentations.open('\some\file.ppt')
$f.ExportAsFixedFormat('\some\newfile.pdf', 2)
Since the "brute force" method didn't work ("type mismatch") I tried to import the enum type with
$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF
$f.ExportAsFixedFormat('\some\newfile.pdf', $pptypepdf)
The strange thing here is that it still throws a "type mismatch" error...
Also, SaveAs works fine with
$f.SaveAs('\some\newfile.pdf', 32) # 32 is for PDF
What am I doing wrong?
Update
Relevant documentation:
Here's the full error message
$pptypepdf= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]::PpFixedFormatTypePDF
$f.ExportAsFixedFormat($filepath, $pptypepdf)
Exception calling "ExportAsFixedFormat" with "2" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"
At line:1 char:23
+ $f.ExportAsFixedFormat <<<< ($filepath, $pptypepdf)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
I've come across the same problem in Python. Try specifying
PrintRange
argument as said in solution by Stefan Schukat:Source: Type mismatch when using export fuction of PowerPoint 2007
I don't know PowerShell at all but have worked out a working example:
This isn't a full solution, but exporting is done. It somehow exports full presentation, not only slide no. 1, as I thought. P.S. Oh. Here's the same solution