Skip to content

Instantly share code, notes, and snippets.

@kalebo
Last active September 20, 2016 02:31
Show Gist options
  • Save kalebo/2c9bb7b0feb65942dc7fbe6f2f93af93 to your computer and use it in GitHub Desktop.
Save kalebo/2c9bb7b0feb65942dc7fbe6f2f93af93 to your computer and use it in GitHub Desktop.
Convert a directory of powerpoint slides to pdfs for lecture notes
'''
' This is a remixed VB script that I adapted from BillP3rd from stackoverflow.
' It expects a existing directory for output and powerpoint to be installed.
'
' Usage: cscript ppxt2pdf.vbs c:\Users\user\class_ppt_dir class_handouts_dir
'
' Also, I hate Visual Basic
'''
Option Explicit
Sub WriteLine ( strLine )
WScript.Stdout.WriteLine strLine
End Sub
Const msoFalse = 0 ' False.
Const msoTrue = -1 ' True.
Const ppFixedFormatIntentScreen = 1 ' Intent is to view exported file on screen.
Const ppFixedFormatIntentPrint = 2 ' Intent is to print exported file.
Const ppFixedFormatTypeXPS = 1 ' XPS format
Const ppFixedFormatTypePDF = 2 ' PDF format
Const ppPrintHandoutVerticalFirst = 1 ' Slides are ordered vertically, with the first slide in the upper-left corner and the second slide below it.
Const ppPrintHandoutHorizontalFirst = 2 ' Slides are ordered horizontally, with the first slide in the upper-left corner and the second slide to the right of it.
Const ppPrintOutputSlides = 1 ' Slides
Const ppPrintOutputTwoSlideHandouts = 2 ' Two Slide Handouts
Const ppPrintOutputThreeSlideHandouts = 3 ' Three Slide Handouts
Const ppPrintOutputSixSlideHandouts = 4 ' Six Slide Handouts
Const ppPrintOutputNotesPages = 5 ' Notes Pages
Const ppPrintOutputOutline = 6 ' Outline
Const ppPrintOutputBuildSlides = 7 ' Build Slides
Const ppPrintOutputFourSlideHandouts = 8 ' Four Slide Handouts
Const ppPrintOutputNineSlideHandouts = 9 ' Nine Slide Handouts
Const ppPrintOutputOneSlideHandouts = 10 ' Single Slide Handouts
Const ppPrintAll = 1 ' Print all slides in the presentation.
Const ppPrintSelection = 2 ' Print a selection of slides.
Const ppPrintCurrent = 3 ' Print the current slide from the presentation.
Const ppPrintSlideRange = 4 ' Print a range of slides.
Const ppPrintNamedSlideShow = 5 ' Print a named slideshow.
Const ppShowAll = 1 ' Show all.
Const ppShowNamedSlideShow = 3 ' Show named slideshow.
Const ppShowSlideRange = 2 ' Show slide range.
'
' This is the actual script
'
Dim inputDirectory
Dim inputFolder
Dim inFiles
Dim outputFolder
Dim inputFile
Dim outputFile
Dim curFile
Dim objPPT
Dim objPresentation
Dim objPrintOptions
Dim objFso
If WScript.Arguments.Count <> 2 Then
WriteLine "You need to specify input files."
WScript.Quit
End If
Set objFso = CreateObject("Scripting.FileSystemObject")
'curDir = objFso.GetAbsolutePathName(".")
Set inputFolder = objFSO.GetFolder(WScript.Arguments.Item(0))
Set outputFolder = objFSO.GetFolder(WScript.Arguments.Item(1))
Set inFiles = inputFolder.Files
Set objPPT = CreateObject( "PowerPoint.Application" )
For Each curFile in inFiles
Set inputFile = curFile
If Not objFso.FileExists( inputFile ) Then
WriteLine "Unable to find your input file " & inputFile
WScript.Quit
End If
objPPT.Visible = TRUE
objPPT.Presentations.Open inputFile
Set objPresentation = objPPT.ActivePresentation
Set objPrintOptions = objPresentation.PrintOptions
objPrintOptions.Ranges.Add 1,objPresentation.Slides.Count
objPrintOptions.RangeType = ppShowAll
WScript.Echo outputFolder & "\" & objFso.GetBaseName(curFile.path) & ".pdf"
objPresentation.ExportAsFixedFormat outputFolder & "\" & objFso.GetBaseName(curFile.path) & ".pdf", ppFixedFormatTypePDF, ppFixedFormatIntentScreen, msoTrue, ppPrintHandoutHorizontalFirst, ppPrintOutputThreeSlideHandouts, msoFalse, objPrintOptions.Ranges(1), ppPrintAll, "Slideshow Name", False, False, False, False, False
objPresentation.Close
Next
ObjPPT.Quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment