#!/usr/local/bin/perl # Originally written by David Anderson (dva@ee.gatech.edu) Oct 7, 1997 # This program is called with the base filename of the .ps file as the # first argument and the title of the html document as the second # argument. For example, to convert resume.ps I would type: # ps2www resume "Resume of David Anderson" # $Log: ps2www,v $ # Revision 1.1 1998/05/06 16:00:46 dva # Initial revision # require 'getopts.pl'; $USAGE = "Usage: ps2www [-l -s -d directory -t directory] filename title\n" . " Where filename is the name of the .ps file *without* the .ps extension\n" . " and title is the title of the HTML document to be produced.\n" . " -l = landscape mode\n" . " -s = seascape mode\n" . " -c = crop white space\n" . " -p = force creation of PDF file\n" . " -d directory = destination directory\n" . " -t directory = temporary directory\n"; $tmpdir = "tmp_"; $destdir= "./"; if ($#ARGV < 1) { print STDERR $USAGE; exit 1; } do Getopts('lscpt:d:'); # -o, -D & -I take arg. Sets opt_* as a side effect. $base = $ARGV[0]; $title = $ARGV[1]; if (! -e "$base.ps") { print STDERR "file not found: $base.ps\n"; print STDERR $USAGE; exit 1; } if ($opt_t) { $tmpdir=$opt_t; } if ($opt_d) { $destdir="$opt_d/"; if (! -e "$destdir") { system "mkdir $destdir"; } system "cp $base.ps $destdir$base.ps"; } $xtra_cmds = ""; if ($opt_c) { $xtra_cmds = "pnmcrop -white | pnmpad -white -l5 -r5 -t5 -b5 |"; } if ($opt_l) { $xtra_cmds = "$xtra_cmds pnmrotate 90 | "; } if ($opt_s) { $xtra_cmds = "$xtra_cmds pnmrotate -90 | "; } $commandstring="gs -dNOPAUSE -sDEVICE=ppmraw -sOutputFile=$tmpdir$base.%d.ppm -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r100 $base.ps -c quit"; open(GS,"|$commandstring"); close(GS); if (($opt_l || $opt_s) && ! -e "$destdir$base.pdf") { print "Warning, this script can only create PDF files\n" . " from portrait oriented originals.\n"; } elsif ((! -e "$destdir$base.pdf") || $opt_p) { if (! $opt_p) { print "No PDF file exists, creating PDF file\n"; } else { print "Creating PDF file\n"; } system "gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=$destdir$base.pdf $base.ps -c quit "; } open(INDEX,"| cat > $destdir$base.html"); print INDEX "\n\n $title\n\n"; print INDEX "\n"; print INDEX "

$title

\n
\n"; print INDEX "

Here is a Postscript version"; if (-e "$destdir$base.pdf") { print INDEX " and here is a PDF version.\n"; print INDEX "

You may obtain Ghostscript and Ghostview for viewing and \n"; print INDEX "printing the Postscript version. The PDF version may be \n"; print INDEX "viewed and printed using "; print INDEX "Adobe Acrobat Reader.\n"; } else { print INDEX ".\n"; print INDEX "

You may obtain Ghostscript and Ghostview for viewing and \n"; print INDEX "printing the Postscript version.\n"; } print INDEX "


\n"; print INDEX "

Or you may view the GIF version in your browser:\n"; print INDEX "

\n"; print INDEX "\n"; $i=1; open(PPM,"ls $tmpdir$base.*.ppm |"); @ppmfiles = ; close(PPM); $N = $#ppmfiles; for ($j=0,$i=1; $j <= $N; ++$j) { $ppmfile = "$tmpdir$base." . $i . ".ppm"; $gif_file = "$base\_$i.gif"; system "ppmquant 256 $ppmfile | $xtra_cmds ppmtogif > $destdir$gif_file"; system("rm $ppmfile \n"); open(WRAP,"| cat > $destdir$base\_$i.html"); print WRAP "\n\n $title (page $i)\n\n"; print WRAP "\n
\n"; if ($j > 0) { $p = $i-1; print WRAP "\n"; } else { print WRAP ""; } print WRAP "\n"; if ($j < $#ppmfiles) { $n = $i+1; print WRAP "\n"; } else { print WRAP ""; } print WRAP "
"; print WRAP "Page $p"; # print WRAP "Page $p"; print WRAP "
 
"; print WRAP "$title"; # print WRAP "
$title"; print WRAP "
"; print WRAP "Page $n"; # print WRAP "Page $n"; print WRAP "
 
\n"; print WRAP "

"; print WRAP "

\n"; print WRAP "
\n"; if ($j > 0) { $p = $i-1; print WRAP "\n"; } else { print WRAP ""; } print WRAP "\n"; if ($j < $#ppmfiles) { $n = $i+1; print WRAP "\n"; } else { print WRAP ""; } print WRAP "
"; print WRAP "Page $p"; # print WRAP "Page $p"; print WRAP "
 
"; print WRAP "$title"; # print WRAP "
$title"; print WRAP "
"; print WRAP "Page $n"; # print WRAP "Page $n"; print WRAP "
 
\n"; print WRAP "
\n\n\n"; close(WRAP); unless ($i-1 & 3) { if ($i > 0) { print INDEX ""; } print INDEX "\n"; } print INDEX "Page $i\n"; $i++; } if ($i > 4) { while ($i-1&3) { $i++; print INDEX " \n"; } } close(PPM); print INDEX "

\n"; print INDEX "
created by"; print INDEX " "; print INDEX "ps2www
\n\n"; close(INDEX);