#!/bin/awk -f # urlfilter.awk # # J. R. Sennnig # Gordon College, Wenham MA # # April 30, 2000 # # Modifed May 9, 2000 # - Change ybot in Portrait mode to work with ink-jet printers which # have rather large margins (e.g. Epson Stylus/Color). # - Changed how title is extracted - now works with empty titles. # - Use page number in PostScript file. # # ************************************************************************** # * WARNING: The paths to two programs (url and date) are hardwired into * # * this program. THESE MUST BE SET CORRECTLY FOR YOUR SYSTEM. * # ************************************************************************** # # This program allows UNIX versions of Netscape to print pages with the # page title and URL at the top of the page, and the page number and date # and time of printing at the bottom of the page. # # Usage: Change the entry in the "Print Command:" field of the Netscape # print window to # # urlfilter.awk | lpr # # This program uses a program by Tim Edward called # url.c (http://bach.ece.jhu.edu/~tim/programs/url.c) which looks for a # Netspace print window on the default X server and obtains the URL of the # page to be printed. # # This is a direct conversion of the program "urlfilter" by # S. Edward Hawkins III of JHU-APL. The orignal version upon which this # is based can be found at http://bach.ece.jhu.edu/~tim/programs/urlfilter. # the header in the original version is: # # show_url: Print filter to overlay page title on output page # author: S. Edward Hawkins III # date: 1999 October 20 # # Unlike both the orignal bash-version of urlfilter and the Perl version # urlfilter.pl (http://bach.ece.jhu.edu/~tim/programs/urlfilter.pl), this # version does not alter the original PostScript code in any way; both the # other versions do change it. In addition, the AWK version runs faster than # either of the other versions. # # I believe that the assumed paper size is US-letter. BEGIN { "/usr/bin/url" | getline url "/bin/date" | getline date page = 0; } /^%%Title:/ { title = substr( $0, length( $1 ) + 1 ); sub( "^[ \t]*", "", title ); # Strip leading white space } /^%%Pages:/ { pages = $2; } /^%%Page:/ { page = $2; } /^%%Orientation:[ \t]*Portrait/ { layout = "portrait"; xpos = 576; ytop = 774; ybot = 50; # Large enough for ink-jet printers } /^%%Orientation:[ \t]*Landscape/ { layout = "landscape"; xtop = 27; xbot = 576; ypos = 756; } /^showpage/ { print "gsave 0 0 translate" print "/Times-Roman findfont 8 scalefont setfont" if ( layout == "portrait" ) { print "36 " ytop " moveto \(" title "\) show" print "%%% GET LENGTH OF URL STRING FOR RIGHT JUSTIFICATION" print "\(" url "\) stringwidth pop " xpos " exch sub" print ytop " moveto \(" url "\) show" print "36 " ybot " moveto \(Page " page " of " pages "\) show" print "%%% GET LENGTH OF DATE STRING FOR RIGHT JUSTIFICATION" print "\(" date "\) stringwidth pop " xpos " exch sub" print ybot " moveto \(" date "\) show grestore" } else if ( layout == "landscape" ) { print xtop " 36 moveto 90 rotate \(" title "\) show -90 rotate" print "%%% GET LENGTH OF URL STRING FOR RIGHT JUSTIFICATION" print "\(" url "\) stringwidth pop " ypos " exch sub" print xtop " exch moveto 90 rotate \(" url "\) show -90 rotate" print xbot " 36 moveto 90 rotate \(Page " page " of " pages "\)" print "show -90 rotate" print "%%% GET LENGTH OF DATE STRING FOR RIGHT JUSTIFICATION" print "\(" date "\) stringwidth pop " ypos " exch sub " xbot print "exch moveto 90 rotate \(" date "\) show grestore" } } { print $0 }