#!/usr/bin/perl -w use strict; my ($file,$line); my $pre=""; my $page=""; my $opts=""; my $nopng=0; $nopng=shift @ARGV if(@ARGV and $ARGV[0] eq "-c"); my $delim="/"; $delim="",shift @ARGV if(@ARGV and $ARGV[0] eq "-d"); $opts.=" -r".shift(@ARGV) if(@ARGV>1 and $ARGV[0] eq "-r" and $ARGV[1] =~ /^[1-9][0-9]*$/s and shift @ARGV); my @thumbs=('yes'); @thumbs=() if(@ARGV and $ARGV[0] eq "-t" and shift @ARGV); die "usage: $0 [-cdt] [-r ] \n" if($#ARGV); open(INPUT,"<$ARGV[0]") or die "open: $!"; ($file=$ARGV[0]) =~ s/\.ps$//; mkdir($file,0777) or die "mkdir: $!" if($delim); unless($nopng) { open(HTML,">$file".($delim?"${delim}index":"").".html") or die "open: $!"; print HTML "Pages from $file\n"; print HTML "
    \n" unless(@thumbs); if($delim) { open(INLINE,">$file${delim}inline.html") or die "open: $!"; print INLINE "Pages from $file (inline)\n"; } } while(defined($line=)) { if($line =~ /^%%Page: (.*) (\d+)\r?\n?$/s) { $page=$2; if($nopng) { open(OUTPUT,">$file$delim$page.ps") or die "open: $!"; } else { if(@thumbs) { print HTML "\n"; } else { print HTML "
  1. $1\n"; } print INLINE "\n" if($delim); open(OUTPUT,"|gs$opts -sDEVICE=pngmono -sOutputFile='$file$delim$page.png' -q - >/dev/null 2>&1") or die "open: $!"; push @thumbs,$page if(@thumbs); } print OUTPUT $pre; print OUTPUT $line; } elsif(length $page) { print OUTPUT $line; } else { $pre.=$line; } } close(INPUT); close(OUTPUT); unless($nopng) { print INLINE ""; close(INLINE); print HTML "
\n" unless(@thumbs); print HTML ""; close(HTML); shift @thumbs; while(@thumbs) { system("convert -sample 100x100 $file$delim$thumbs[0].png $file$delim$thumbs[0]t.png") and die "system: $!"; shift @thumbs; } } 0;