Remediating PowerPoint

ziggy on 2002-05-16T19:10:52

Lambda the Ultimate had an interesting story yesterday about domain-specific languages.

  • Bad news: it was done with PowerPoint.
  • Good news: the presentation was converted to HTML
  • Bad news: That interface sucks; it's slow, it requires scrolling in my rather large mozilla window, and it's slow to click back and forth between slides
  • Good news: Perl to the rescue!
This little hack takes individual, interleaved GIF slides and turns them into a much more user-friendly PDF:
#!/usr/bin/perl -w

use strict;
use PDFLib;

my $pdf = new PDFLib (
				filename    => "slides.pdf",
				papersize   => "letter",
				orientation => "landscape",
				creator     => "Paul Hudak",
				title       => "The Promise of Domain Specific Languages",
);

foreach (<*.gif>) {
	my ($stem) = m/(.*?).gif/;

	print STDERR "$stem\n";
	`convert $stem.gif $stem.png`;

	my $img = $pdf->load_image(filetype => "png", filename => "$stem.png",);
	$pdf->start_page();
	$pdf->add_image(img => $img, x => 0, y => 0);
	$pdf->end_page();

	unlink ("$stem.png");
}
Many thanks to Matt Sergeant for the PDFLib module. I actually spent more time looking at the module documentation than I did writing and testing this code. :-)

Now back to that presentation about DSLs...


Hah!

Matts on 2002-05-16T21:35:58

Excellent idea! Those types of GIF'd presentations always annoyed me - it never occured to me to use my own code to create PDF's.

My only sadness about PDFLib is that I can't freely use the underlying library pdflib in a commercial setting. I wish there were a complete free alternative. I hade a look at the PDF spec a few weeks ago (in a book available from Adobe) and it's a bit heavyweight, so I won't be writing an XS module just yet ;-)

Oh yeah, that and I can't get it to do Unicode, no matter how hard I try.

Re:Hah!

ziggy on 2002-05-16T22:04:53

I vaguely remember a discussion about this a few months ago. What are the issues involved? According to the business topics page, the only commercial issues involve shipping commercial products that incorporate PDFlib. Use in a commercial setting seems OK.

As to the PDF spec, it's dense, but comprehesible. There's a lot of prior art involved as well, so PDF falles under the "exceedingly well documented" umbrella (modulo PDF Forms). If only that were true of RTF, which looks like a TeX-influenced bad acid trip, with a spec (v1.5) that's about as clear (once you pry it away from its forgotten ghetto of the web).

Re:Hah!

Matts on 2002-05-16T22:46:59

You can't run a web site where you make money that uses PDFLib. Their license forbids it (obviously unless you have a commercial license from them). I think this makes axkit.org actually illegal, since I host ads there (I should remove them since they pay so little) and I serve presentations generated with AxPoint.

Re:Hah!

gav on 2002-05-17T04:04:37

There seems to be lots of PDF modules on cpan including: I looked over these a few months back and found the lack of documentation and examples quite daunting. I can't use PDFLib due as everything I do at work is in a commerical setting :) Has anyone had any luck with these modules?

On reading and working with existing PDFs I've actually had more luck using pdftohtml (not to be confused with pdf2html!) and then post-processing using HTML::TreeBuilder.