Skip to content

Instantly share code, notes, and snippets.

@mjfusa
Created February 11, 2022 20:57
Show Gist options
  • Save mjfusa/4cb34dfc0a978964d2d693b9d6d50843 to your computer and use it in GitHub Desktop.
Save mjfusa/4cb34dfc0a978964d2d693b9d6d50843 to your computer and use it in GitHub Desktop.
PowerShell: PPT to PDF - Recurse
<#
.Synopsis
ConverToPDF converts PowerPoint files to pdf and saves the output into the \pdf current folder.
.DESCRIPTION
ConverToPDF converts PowerPoint files to pdf and saves the output into the \pdf current folder.
.NOTES
Created by: Paul Lim paullim@ncs.com.sg
Modified: 18/03/2019
Changelog:
* First version
To Do:
*
.PARAMETER None
None
.EXAMPLE
Run this script under the same folder as all the PowerPoint files.
It will open each PPTX file and saves it as PDF under a newly created \pdf folder.
.LINK
#>
# Create folder to store pdf output
New-Item -Path $PSScriptRoot\pdf -ItemType directory -Force
Get-ChildItem $PSScriptRoot -File -Filter *pptx -Recurse |
ForEach-Object -Begin {
$null = Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint
$SaveOption = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsPDF
$PowerPoint = New-Object -ComObject "PowerPoint.Application"
} -Process {
$Presentation = $PowerPoint.Presentations.Open($_.FullName)
$PdfNewName = $PSScriptRoot + "\\pdf\\" + $_.Name -replace '\.pptx$','.pdf'
$Presentation.SaveAs($PdfNewName,$SaveOption)
$Presentation.Close()
} -End {
$PowerPoint.Quit()
Stop-Process -Name POWERPNT -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment