I would like to export PowerPoint to PDF via powershell.
I tried writing as below, but PowerPoint.Application.PpFixedFormatType:TypeName doesn't recognize it well.
$Path=".\testpdf.pdf"
$mtrue=[Microsoft.Office.Core.MsoTriState]:msoTrue
$mfalse=[Microsoft.Office.Core.MsoTriState]:msoFalse
$ppt = New-Object-ComObject PowerPoint.Application
$pre=$ppt.Presentations.Open($Path,$mfalse,$mtrue,$mtrue)
$FixedFormatType= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]:ppFixedFormatTypePDF
$pre.ExportAsFixedFormat($Path, $FixedFormatType)
The error will appear as follows:
An exception occurred while setting "ExportAsFixedFormat": "ppFixedFormatTypePDF" value of type "PpFixedFormatType" to type "Object"
Unable to convert.
Location line: 1 character: 1
+ $pre.ExportAsFixedFormat($Path, $FixedFormatType)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: NotSpecified:(:)[], MethodException
+ Fully QualifiedErrorId: RuntimeException
I have confirmed that PDF conversion is possible using the SaveAS method, but I am worried that ExportAsFixedFormat will fail.
Thank you for your cooperation.
I experimented with the link you gave me in the comment and succeeded in outputting it with the code below.
It is optional on the MS site, but is it necessary?
MS site
$ppt=New-Object-ComObject PowerPoint.Application
$mtrue=[Microsoft.Office.Core.MsoTriState]:msoTrue
$mfalse=[Microsoft.Office.Core.MsoTriState]:msoFalse
$pre=$ppt.Presentations.Open($Sfile,$mfalse,$mtrue,$mtrue)
$FixedFormatType= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatType]:ppFixedFormatTypePDF
$Intent= [Microsoft.Office.Interop.PowerPoint.PpFixedFormatIntent]:ppFixedFormatIntentScreen
$FrameSlides=$mfalse
$HandoutOrder= [Microsoft.Office.Interop.PowerPoint.PpPrintHandoutOrder]:ppPrintHandoutVerticalFirst
$OutputType=[Microsoft.Office.Interop.PowerPoint.PpPrintOutputType]:ppPrintOutputSlides
$PrintHiddenSlides=$mfalse
$sNUM = $pre.Slides.count
$pre.PrintOptions.Ranges.Add (1,$sNUM)
$PrintRange=$pre.PrintOptions.Ranges.Item(1)
$pre.ExportAsFixedFormat($Path, $FixedFormatType, $Intent, $FrameSlides, $HandoutOrder, $OutputType, $PrintHiddenSlides, $PrintRange)
© 2024 OneMinuteCode. All rights reserved.