#!/usr/local/bin/perl
#####################################################################################
# PRINTPRP.PL ©1998 Bruce Quackenbush of Art Works Studio
# bruceq@artworksstudio.com
# http://www.artworksstudio.com
#
# PrintPrep 1.0 will convert a given HTML document into "Printable" form. That is,
# it will disable any background graphics, set the background color to white, set
# all text colors to black, and insert
's wherever you place a custom tag
# in the HTML document. It was written for websites with dark backgrounds and
# light text. The client wanted folks with older browsers to be able to print
# the pages, and I wanted to design with a dark grey background
# (http://www.mizelarts.org). This was my solution.
#
# I don't believe there is any Perl 5 specific syntax in this script but I
# can't be entirely sure. Let me know if it doesn't work with Perl 4.
#
# One URI encoded argument - f - as the full name of the page (no path)
#
# To use this script, set the few variables below, place this script in your
# site's CGI folder, and include a link like this on your pages:
#
# printable page
#
# Feel free to use and modify this script however you like, but if you make
# anything really cool you have to send me a copy! I'd appreciate it
# if you kept this header in the file too.
#
# No warranties expressed or implied. I'll help you if you have problems
# with it, but I won't teach anybody Perl. ;)
#####################################################################################
# set the string that will be inserted in front of the closing tag
# this is to force the browser to reload the new temp file each time it is re-created
$nocache = q{
};
# Set the Path Back to the HTML files
# This can either be the path to the folder containing the calling pages - relative
# to the folder containing this script, or an absolute path of the folder with the
# HTML pages. If you are on a WinNT server be sure to use backslashes but "escape"
# them (with backslashes).
$pathback = "../";
# Set the output file name
# Using $pathback you output the temporary file to the same folder as the
# calling file, thereby maintaining all relative links from the original page.
$htoutfile = $pathback . "forprint.htm";
# Set up the string replacement hash with regular expresions, using the format:
# matchstring => substitutestring, (be sure to put the comma on the end)
%strrep = (
qq( TEXT="?#.{6}"?) => qq{ TEXT="#000000"},
qq( LINK="?#.{6}"?) => qq{ LINK="#000000"},
qq( VLINK="?#.{6}"?) => qq{ VLINK="#000000"},
qq( BGCOLOR="?#.{6}"?) => qq{ BGCOLOR="#FFFFFF"},
qq{} => qq{$nocache },
qq{ BACKGROUND=} => qq{ },
qq{ COLOR=} => qq{ },
qq{} => qq{
},
);
#####################################################################################
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$contents{$name} = $value;
}
$htmfile = $pathback . $contents{'f'};
# load the file into an array of lines
open (HTMIN,"<$htmfile") or die("Cannot open $htmfile -- Check Argument in Link: $!");
@lines=;
close (HTMIN);
# replace all relevant tags and attributes with printable equivalents
foreach $line (@lines) {
foreach $key (keys %strrep) {
$line =~ s/$key/$strrep{$key}/i;
}
}
# output the converted file
open (HTMOUT,">$htoutfile") or die("Cannot open $htoutfile -- Check Directory Perms: $!");
foreach $line (@lines) {
print HTMOUT $line;
}
close (HTMOUT);
# send the browser to the newly created page
print "Location: $htoutfile\n\n";
exit;