PowerShell: PPT to PDF - Recurse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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