├── .project ├── .pydevproject ├── README └── pptx-export-notes.py /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | pptx_export_speaker_notes 4 | 5 | 6 | 7 | 8 | 9 | org.python.pydev.PyDevBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.python.pydev.pythonNature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.pydevproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | /pptx_export_speaker_notes 7 | 8 | python 2.7 9 | Default 10 | 11 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | pptx-export-notes 2 | 3 | v1 4 | by Eric Jang 5 | 6 | a simple script to extract the presenter notes from a .pptx file and export them into a single plaintext (.txt) file (for printing/rehearsing). 7 | 8 | Usage: 9 | 10 | pptx_export_speaker_notes.py -p /Users/Eric/Desktop/myppt.pptx 11 | 12 | A .txt file containing all of the presenter notes will be exported to the same directory as the .pptx file. 13 | 14 | This only works for .pptx files as they use Microsoft's OpenXML format (will not work for ppt files). 15 | 16 | -------------------------------------------------------------------------------- /pptx-export-notes.py: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | ############################################################################# 3 | ### ### 4 | ### pptx notes exporter v1.0 copyright Eric Jang 2012 ### 5 | ### ericjang2004@gmail.com ### 6 | ### ### 7 | ############################################################################# 8 | ############################################################################# 9 | 10 | #!/usr/bin/env python 11 | import argparse, os, glob 12 | from zipfile import ZipFile 13 | from xml.dom.minidom import parse 14 | 15 | 16 | def slide_number_from_xml_file(filename): 17 | """ 18 | Integer slide number from filename 19 | 20 | Assumes /path/to/Slidefile/somekindofSlide36.something 21 | """ 22 | return int(filename[filename.rfind("Slide") + 5:filename.rfind(".")]) 23 | 24 | #main function 25 | def run(): 26 | parser = argparse.ArgumentParser(description='exports speaker notes from pptx files by parsing the XML') 27 | parser.add_argument('-v', action='version', version='%(prog)s 1.0') 28 | parser.add_argument('-p', metavar='', help='path to the Powerpoint 2007+ file', action='store', 29 | type=file, dest='pptxfile') 30 | #add more arguments here in future if you wish to expand 31 | args = parser.parse_args() 32 | #extract the pptx file as a zip archive 33 | #note: only extract from pptx files that you trust. they could potentially overwrite your important files. 34 | ZipFile(args.pptxfile).extractall(path='/tmp/', pwd=None) 35 | path = '/tmp/ppt/notesSlides/' 36 | 37 | notesDict = {} 38 | #open up the file that you wish to write to 39 | writepath = os.path.dirname(args.pptxfile.name) + '/' + os.path.basename(args.pptxfile.name).rsplit('.', 1)[ 40 | 0] + '_presenter_notes.txt' 41 | print writepath 42 | 43 | # Get the xml we extracted from the zip file 44 | xmlfiles = glob.glob(os.path.join(path, '*.xml')) 45 | 46 | with open(writepath, 'w') as f: 47 | for infile in sorted(xmlfiles, key=slide_number_from_xml_file): 48 | #parse each XML notes file from the notes folder. 49 | dom = parse(infile) 50 | noteslist = dom.getElementsByTagName('a:t') 51 | if len(noteslist) == 0: 52 | continue 53 | 54 | #separate last element of noteslist for use as the slide marking. 55 | slideNumber = slide_number_from_xml_file(infile) 56 | #start with this empty string to build the presenter note itself 57 | tempstring = '' 58 | 59 | for node in noteslist: 60 | xmlTag = node.toxml() 61 | xmlData = xmlTag.replace('', '').replace('', '') 62 | #concatenate the xmlData to the tempstring for the particular slideNumber index. 63 | tempstring = tempstring + xmlData 64 | 65 | #store the tempstring in the dictionary under the slide number 66 | notesDict[slideNumber] = tempstring 67 | 68 | #print/write the dictionary to file in sorted order by key value. 69 | for x in [key for key in sorted(notesDict.keys(), key=int)]: 70 | f.write('Slide ' + str(x) + '\n') 71 | notes_string = notesDict[x] 72 | f.write(notes_string.encode('utf-8', 'ignore') + '\n') 73 | 74 | print 'file successfully written to' + '\'' + writepath + '\'' 75 | 76 | 77 | if __name__ == "__main__": 78 | try: 79 | run() 80 | except (KeyboardInterrupt, SystemExit): 81 | raise 82 | 83 | --------------------------------------------------------------------------------