#!/usr/bin/perl -w # If your perl isn't in /usr/bin then change the path above # to reflect this sad fact. # This little perl script was hacked together by Jens G Jensen # and is distributed, as usual, without warranties of any kind # etc blah blah, and under the Perl Artistic License in case # you're interested. use strict; # get the basename, assuming 'reasonable' characters are used my $name = $0 =~ /[-_a-zA-Z0-9.]+$/ ? $& : $0; # read options, if any my $sc = 1; my $pl = 'ur'; my ($dx, $dy) = (0, 0); while( @ARGV && $ARGV[0] =~ /^-((u|l)(l|r)|sc)$/ ) { my $opt = shift @ARGV; if( $1 eq 'sc' ) { $sc = shift @ARGV; unless( $sc =~ /^\d*\.?\d*$/ ) { print STDERR "$name: Warning: bad value $sc for -sc\n"; unshift @ARGV, $sc; $sc = 1; } } else { $pl = $1; if( @ARGV && $ARGV[0] =~ /^(\d+),?(\d+)?$/ ) { shift @ARGV; $dx = $1; $dy = $2 ? $2 : $1; } } } unless( @ARGV ) { print STDERR < [ ] where options ::= placement [scale] | scale [placement] placement ::= -ul | -ur | -ll | -lr [[,]] scale ::= -sc and logofile should be an EPS file with your logo (this file must be seekable), and inputfile should be some Postscript file (if omitted, standard input is used). $name will insert the eps file at the head of each page (this is wasteful, but what do you expect from a quick hack anyway?) so that it will print appropriately. Placement allows you to place relative to upper left (etc) corner, with an optional offset from the corner (in postscript points, 1/72 of an inch). If you specify two numbers, separated by a comma and with no spaces between them, then the first is offset in x-direction and the second in y-direction. BUGS: ignores orientation, doesn't handle (atend) boundingbox in ps file. USAGE exit(0); } my $fname = @ARGV > 1 ? $ARGV[1] : "-"; open(IN, "<$fname") or die "$name: Cannot open $fname for reading"; my (@bigbox, @smallbox); # grep logofile for the boundingbox open(EPS, "<$ARGV[0]") or die "$name: Cannot open include file $ARGV[0] for reading"; while() { if(/^%%BoundingBox:\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/) { @smallbox = ($1, $2, $3, $4); last; } } unless( defined @smallbox ) { print STDERR "$name: Fatal: I didn't find a valid boundingbox in $ARGV[0]\n"; exit(1); } # Offset for placing the EPS within BBox my ($x, $y) = (undef, undef); while() { print; if(/^%%BoundingBox:\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*$/) { @bigbox = ($1, $2, $3, $4); } if( /^%%Page:/ ) { unless( defined $x ) { unless( defined @bigbox ) { print STDERR <) { print unless /^%%(Page)?BoundingBox:/; } print <