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(); | |
} |
Have you had any success using this with O365? I think they have pulled the interop module.
I haven't used this script since 2017, but I just tried it with the current version of PowerPint.
I could not get the export to work, but the COM Interop API still seems to be in place, so in principle I think this should still work.
Thanks for trying.
What version are you running? 2019?
I'm Microsoft 365 Apps v. 2210 and I failed to load the assemblies. Read a
few reports office had dropped the interop api.
…On Sat, 5 Nov 2022, 22:42 Andreas Grünwald, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
I haven't used this script since 2017, but I just tried it with the
current version of PowerPint.
I could not get the export to work, but the COM Interop API still seems to
be in place, so in principle I think this should still work.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/5c5f5aadb885fe918000b248e5dd6e36#gistcomment-4359661>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALRDEQ3DSI4DXFAPYRZJB5TWG3PHDBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA2DGNZRHAZDKOFHORZGSZ3HMVZKMY3SMVQXIZI>
.
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>
.
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
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
@wale-A If you want to export all slides as JPG you can do it by using the
Export
method on the$presentation
object. So it would be$presentation.Export($outputFile, "JPG", $width, $height)
.$width
and$height
are optional parameters that you can use to specify the resolution of the exported image files. If not specified, the default resolution of 96 dpi will be used.