Created
January 11, 2017 20:25
-
-
Save ap0llo/5c5f5aadb885fe918000b248e5dd6e36 to your computer and use it in GitHub Desktop.
# Powershell script to export Powerpoint slides as jpg images using the Powerpoint COM API
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
# Powershell script to export Powerpoint slides as jpg images using the Powerpoint COM API | |
function Export-Slide($inputFile, $slideNumber, $outputFile) | |
{ | |
# Load Powerpoint Interop Assembly | |
[Reflection.Assembly]::LoadWithPartialname("Microsoft.Office.Interop.Powerpoint") > $null | |
[Reflection.Assembly]::LoadWithPartialname("Office") > $null | |
$msoFalse = [Microsoft.Office.Core.MsoTristate]::msoFalse | |
$msoTrue = [Microsoft.Office.Core.MsoTristate]::msoTrue | |
# start Powerpoint | |
$application = New-Object "Microsoft.Office.Interop.Powerpoint.ApplicationClass" | |
# Make sure inputFile is an absolte path | |
$inputFile = Resolve-Path $inputFile | |
$presentation = $application.Presentations.Open($inputFile, $msoTrue, $msoFalse, $msoFalse) | |
$slide = $presentation.Slides.Item($slideNumber) | |
$slide.Export($outputFile, "JPG") | |
$slide = $null | |
$presentation.Close() | |
$presentation = $null | |
if($application.Windows.Count -eq 0) | |
{ | |
$application.Quit() | |
} | |
$application = $null | |
# Make sure references to COM objects are released, otherwise powerpoint might not close | |
# (calling the methods twice is intentional, see https://msdn.microsoft.com/en-us/library/aa679807(office.11).aspx#officeinteroperabilitych2_part2_gc) | |
[System.GC]::Collect(); | |
[System.GC]::WaitForPendingFinalizers(); | |
[System.GC]::Collect(); | |
[System.GC]::WaitForPendingFinalizers(); | |
} |
Yes using powershell 7. Will see if I can use the windows version, it makes
sense if the module isn't Net core compatible and needs all the Windows
apis to work.
…On Mon, 7 Nov 2022, 18:42 Andreas Grünwald, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
I'm using the Microsoft 365 version 2210.
Which version of Powershell are you using?
Loading the Assembly seems to work fine on Windows PowerShell/PowerShell 5
but it doesn't work for me on PowerShell Core/PowerShell 7
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/5c5f5aadb885fe918000b248e5dd6e36#gistcomment-4361413>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALRDEQY3UKQCW5FUJVFUQQ3WHFEQLBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA2DGNZRHAZDKOFHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on a thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using the Microsoft 365 version 2210.
Which version of Powershell are you using?
Loading the Assembly seems to work fine on Windows PowerShell/PowerShell 5 but it doesn't work for me on PowerShell Core/PowerShell 7