#!/usr/bin/perl -w # Example 3-3. PDFconvert.pl use strict; use Image::Magick; # Retrieve the arguments provided on the command line my @files = @ARGV; die "You must provide a list of PDF files.\n" unless (@files); my $img = new Image::Magick; # To only read the first page from each PDF file we must append # the string '[0]' to each of the file names my @files2read = map { 'pdf:'.$_.'[0]' } @files; print STDERR "Reading files...\n"; my $status = $img->Read(@files2read); if ($status) { die $status; } # Create the thumbnails my $montage = $img->Montage(geometry=>"150x150", tile=>'1x1', borderwidth=>2, mode=> 'Frame', label=>'%f', ); # Rather than let Image::Magick name each file, we want to # control the naming scheme, so we'll write out each image from this loop. for (my $i=0; $i < @$img+0; $i++) { print STDERR "Writing thumb$i.gif\n"; $montage->[$i]->Write("gif:thumb$i.gif"); } # Now create an index HTML file with links to each of the # original documents and include the image of each first page # as the content of each hyperlink. print STDERR "Writing pdf_index.html\n"; open OUT, ">pdf_index.html" or die("Couldn't open image!\n"); print OUT "
"; for (my $i=0; $i < @files+0; $i++) { print OUT qq(