#!/usr/bin/perl -w

# script written by K.-H. Herrmann June 2005
# creates a Open Office Impress presentation from
# a list of images (assuming full page images)
# get "high" res images with:
# gs -dNOPAUSE -r300 -sDEVICE=pngalpha -sOutputFile=testoutput_%d.png  -dBATCH file.pdf
# 
# for LaTeX/beamer slides the following produces exactly 1024x768 images
#
#gs -dNOPAUSE -g1024x768 -r205 -sDEVICE=pngalpha \
# -sOutputFile=Talkimg_%d.png  -dBATCH Talk.pdf

use OpenOffice::OODoc;


if ((@ARGV <1) or (@ARGV > 2)){
  print << "EOF";
  Usage:
  img2ooImpress.pl ImageFileList [outputfile.swi]
  ImageFileList is a file containing all images to import
  in the right sequence.
EOF

exit;
}
my $outputfile;
my $imgFileList=shift;
$outputfile="img2ooImpressExport.swi" unless $outputfile=shift;

open (IN,"<$imgFileList") or die "Can't read $imgFileList\n";


my $document = ooDocument
  (
   file            => $outputfile,
   create          => 'presentation'
  );

$document->createImageStyle("slide");

my $i=1;
while (my $imgfile=<IN>){
  chomp($imgfile);

  my $test=  $document->appendElement
    ('//office:body',0,'draw:page');

my $image=  $document->createImageElement
    (
     "Slide".$i,
     description     => "image ".$i." filename:".$imgfile,
     page            => $test,
     position        => "0,0",
     import          => $imgfile,
     size            => "28cm, 21cm",
     style           => "slide"
    );

$i++;

}

$document->save;

