Convert-PPTX to PDF

As frequent speakers at conferences, it is always necessary for us to convert our presentations to PDF files to share them afterwards with the community. Unfortunately, this can easily become a very time-consuming job if you need to open many different and large PowerPoint files. The following function does this job for you automatically:

<#
.Synopsis
Convert PowerPoint files to pdf.
.DESCRIPTION
Convert PowerPoint files to pdf. Searches recursively in complete folders.
.EXAMPLE
Convert-PPTXtoPDF -Path c:Workshops
#>
function Convert-PPTXtoPDF
{
[CmdletBinding()]
Param
(
# Folder or File
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $false,
Position = 0)]
$Path
)
#Load assembly.
$null = Add-Type -AssemblyName Microsoft.Office.Interop.PowerPoint

#Store SaveOption
$SaveOption = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsPDF

#Open PowerPoint ComObject
$PowerPoint = New-Object -ComObject 'PowerPoint.Application'

#Retrieve all pptx elements recursively.
Get-ChildItem $Path -File -Filter *pptx -Recurse |
ForEach-Object -Begin {
} -Process {

#create a pdf file for each found pptx file
$Presentation = $PowerPoint.Presentations.Open($_.FullName)
$PdfNewName = $_.FullName -replace '.pptx$', '.pdf'
$Presentation.SaveAs($PdfNewName,$SaveOption)
$Presentation.Close()
} -End {

#Close Powerpoint after the last conversion
$PowerPoint.Quit()

#Kill process
Stop-Process -Name POWERPNT -Force
}
}

This is a great example of how to work with ComObjects. As you can see, after you have loaded the assembly, and the ComObject has been instantiated for PowerPoint.Application, you can make direct use of it and will also be able benefit from IntelliSense. There are many ComObjects out there in frequent use. As a rule, you should always search for dedicated cmdlets before implementing solutions through the use of ComObjects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.67.251