Skip to content

Instantly share code, notes, and snippets.

@tiwo
Last active July 10, 2023 01:13
Show Gist options
  • Save tiwo/f3900653855132c8d26377394a9c29b4 to your computer and use it in GitHub Desktop.
Save tiwo/f3900653855132c8d26377394a9c29b4 to your computer and use it in GitHub Desktop.
ppt2jpeg.vbs: Convert Powerpoint slides to JPEG images

ppt2vbs

export a Powerpoint presentation to JPEG images, one per slide. Used as a workaround to the broken JPEG export in Powerpoint itself, which yields only low quality images.

Usage

You can adjust the image resolution by varying the numerical argument in line 46, in the call to ExportSlides.

Just drag and drop one or more PPT or PPTX files onto the vbs script. The script will process each, showing a short message, and create Image files named like example.pptx-0001.jpg.

From the command line, call cscript ppt2jpeg.vbs [example.pptx] [next.pptx] ....

License

Copyright 2016-2017 tiwocode@gmail.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function FormatNumberLeadingZeroes(expr, digits)
remain = expr
Do
result = CStr(remain mod 10) & result
remain = remain \ 10
Loop Until (remain = 0) and (Len(result) >= digits)
FormatNumberLeadingZeroes = result
End Function
function ExportSlides(ppt_file, out_format, megapixels)
Set pptApp = CreateObject("PowerPoint.Application")
Set ppt = pptApp.Presentations.Open(ppt_file, True, , False)
With ppt.PageSetup
sh = .SlideHeight
sw = .SlideWidth
End With
sA = sh * sw
factor = Sqr(1000000.0 * megapixels / sA)
imageheight = Round(factor * sh, 0)
imagewidth = Round(factor * sw, 0)
num_exported = 0
For Each slide in ppt.Slides
slide.Export ppt_file & "-" _
& FormatNumberLeadingZeroes(slide.SlideIndex, 4) _
& "." & LCase(out_format), _
out_format, _
imagewidth, imageheight
num_exported = num_exported + 1
Next
ExportSlides = num_exported
End Function
For Each arg in Wscript.Arguments
' adjust megapixels here in the last argument:
num_exported = ExportSlides(arg, "JPG", 4)
WScript.Echo "Done with ", arg, ". ", num_exported, " slides exported."
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment