I would like to export PowerPoint to PDF via powershell.

Asked 2 years ago, Updated 2 years ago, 444 views

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.

windows powershell powerpoint

2022-09-30 21:59

1 Answers

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)


2022-09-30 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.