#!/usr/bin/perl -w # # $Id: saveps,v 1.2 2004/02/22 01:21:10 vogelke Exp $ # # NAME: # saveps # # SYNOPSIS: # saveps [-v] url # # DESCRIPTION: # Save browser PostScript to a temporary file. # # OPTIONS: # "-v" prints the current version and exits. # # NOTES: # I got sick of Netscape not including line numbers or the URL # when it prints, so I wrote something to modify the PostScript # on the fly. # # When I click "Print", my default is to go to a program instead # of a file, so I just cut/paste the URL and pass that as an # argument to a script called "saveps". I was hoping that # Netscape would somehow keep the URL in the environment or as # a comment in the generated PostScript, but unfortunately that # doesn't seem to be the case. # # The script saves the modified PostScript to a file called # /tmp/saveps$$. The URL appears in the top-left corner of each # page, and the page number appears in the top-right corner. # I save to a file instead of printing directly, in case I want # to use other scripts for printing 4-up or double-sided, etc. # # AUTHOR: # Karl Vogel # Sumaria Systems, Inc. use strict; use warnings; $ENV{"PATH"} = "/bin:/usr/sbin:/usr/local/bin"; my ($myname); # script basename. my ($page); # page number, top right corner of page. my ($save); # generated PostScript. my ($url); # URL, top left corner of page. my ($vers); # current version. #--------------------------------------------------------------------- # Handle command line arguments (if any). ($myname) = split (/\//, reverse ($0)); $myname = reverse ($myname); usage() unless getopts ("v"); $vers = version(); exit(0, $vers) if $opt_v; # # Filter PostScript, adding page number and URL. # #chomp ($save = `mktemp /tmp/$myname.XXXXXX`); # safer. $save = "/tmp/$myname.$$"; $url = shift (@ARGV); $page = 0; open (SAVE, "> $save") || die "$save: can't write: $!\n"; while (<>) { print SAVE; if (/^..BeginPageSetup/) { $page++; print SAVE "\% START add URL\n"; print SAVE "54 750 moveto 10 f0\n"; print SAVE "($url) show\n"; print SAVE "550 750 moveto 10 f0\n"; print SAVE "($page) show\n"; print SAVE "\% END add URL\n"; } } close (SAVE); exit (0);