use strict; use warnings; use Win32::OLE; use HTML::Template; # -------------------------------------------------------------------------- # Useful constants # -------------------------------------------------------------------------- use constant OPENDIR => "c:/"; use constant OUTPUTDIR => OPENDIR . "output/"; use constant IMAGEDIR => OUTPUTDIR . "images"; # -------------------------------------------------------------------------- # Read in that there filename - shift to getopts when we have more options. # -------------------------------------------------------------------------- my $file = shift @ARGV; unless(defined($file)) { print "Usage: ppt_parser.pl \n"; exit(0); } # Check the file exists unless( -f $file) { print "Error: file not found\n"; exit(0); } # -------------------------------------------------------------------------- # Create a handle to the Powerpoint Application object. # -------------------------------------------------------------------------- my $powerpoint = Win32::OLE->GetActiveObject('PowerPoint.Application'); # Create the target dir mkdir("output"); unless(defined($powerpoint)) { print "Error: could not create powerpoint object\n"; exit(); } # -------------------------------------------------------------------------- # Create the presentations collection and open our presentation file. An odd # way of doing it but hey - what do I know. # -------------------------------------------------------------------------- my $presentationcoll = $powerpoint->Presentations(); $presentationcoll->Open(OPENDIR . $file); # -------------------------------------------------------------------------- # Now we've loaded it, its the active presentation. So we can access that # via the active presentation object. How nice. # -------------------------------------------------------------------------- my $active = $powerpoint->ActivePresentation(); # -------------------------------------------------------------------------- # And we export all the slides as PNG files. Override this to allow JPG # files as well when we use getopts. # -------------------------------------------------------------------------- $active->Export(IMAGEDIR,"png",400,400); # -------------------------------------------------------------------------- # Now we build the HTML. We go through our list of slides and create a # web page for each. We must use a template or a default. The default will # be loaded via __DATA__. # -------------------------------------------------------------------------- unless(opendir(DIR,IMAGEDIR)) { print "Error: files created but could not read target directory\n"; } my @list = readdir(DIR); close(DIR); my $length = $#list; # -------------------------------------------------------------------------- # Load the web page template and create our template object. # -------------------------------------------------------------------------- my @data = ; shift @data; # remove extraneous __DATA__ shift @data; my $parser = HTML::Template->new( arrayref => \@data, die_on_bad_params => 0 ); $parser->param('title', 'Slideshow Bob'); $parser->param('bgcolor', '#FFFFFF'); # -------------------------------------------------------------------------- # Create each page with the appropriate back and next links # -------------------------------------------------------------------------- for(my $i = 1; $i < $length; $i++) { if($i != 1) { $parser->param("previous",1); $parser->param("previous_link","slide_" . ($i -1 ) . ".html"); } if($i != ($length -1)) { $parser->param("next",1); $parser->param("next_link",'slide_'. ($i +1) . '.html'); } else { $parser->param("next",0); } # Through hoops we shall jump. my $var = $active->Slides($i)->NotesPage->Shapes->Placeholders(2)->TextFrame->TextRange()->Text(); if(defined($var)) { $parser->param("notes",$var); } else { $parser->param("notes",""); } $parser->param("image_name","Slide$i.PNG"); my $output = $parser->output(); open(FH,'>' . OUTPUTDIR . "slide_$i.html"); print FH $output; close(FH); } $active->Close(); __END__ __DATA__ <TMPL_VAR NAME="title"> ">

">

">Previous    ">Next