Save your powerpoint presentation using a template with HTML::Template directives in it. Avoid having to use the default output of frames, activex objects etc. You need to specify the Powerpoint file on the command line and for some reason, you need to have Powerpoint running. The constants for loading and saving the output need altering accordingly. I could have used getopts but this solved a problem quickly for me. Saves images as PNG and notes as text in the HTML.
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 opt
+ions.
# --------------------------------------------------------------------
+------
my $file = shift @ARGV;
unless(defined($file))
{
print "Usage: ppt_parser.pl <filename>\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 t
+hat
# via the active presentation object. How nice.
# --------------------------------------------------------------------
+------
my $active = $powerpoint->ActivePresentation();
# --------------------------------------------------------------------
+------
# And we export all the slides as PNG files. Override this to allow JP
+G
# 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 = <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__
<html>
<head>
<title><TMPL_VAR NAME="title"></title>
</head>
<body bgcolor="<TMPL_VAR NAME="bgcolor">">
<p>
<img src="images/<TMPL_VAR NAME="image_name">">
</p>
<p>
<TMPL_VAR NAME="notes">
</p>
<p>
<TMPL_IF NAME="previous">
<a href="<TMPL_VAR NAME="previous_link">">Previous</a>
</TMPL_IF>
<TMPL_IF NAME="next">
<a href="<TMPL_VAR NAME="next_link">">Next</a>
</TMPL_IF>
</p>
</body>
</html>