home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- From: andyr@wizzy.com (Andy Rabagliati)
- Subject: v32i089: envelope - Perl Envelope Addresser tool, v2, Part01/01
- Message-ID: <1992Sep21.000624.5611@sparky.imd.sterling.com>
- X-Md4-Signature: c7153b8bfe2b8357079e0458c0a6283e
- Date: Mon, 21 Sep 1992 00:06:24 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: andyr@wizzy.com (Andy Rabagliati)
- Posting-number: Volume 32, Issue 89
- Archive-name: envelope/part01
- Environment: Perl, SGI, HPLJ, PostScript
- Supersedes: envelope: Volume 22, Issue 59
-
- Envelope Addresser tool, Perl script.
-
- Given an address, either from stdin or a file argument, addresses a
- commercial envelope, including generating postal bar codes, on your
- HP Laserjet II or III printer or compatible, or PostScript printer.
-
- -------------
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of shell archive."
- # Contents: README env.pl
- # Wrapped by andyr@wizzy on Fri Sep 18 18:09:44 1992
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(2670 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- XEnvelope Addresser tool, Perl script.
- XGiven an address, either from stdin or a file argument,
- Xaddresses a commercial envelope, including generating postal
- Xbar codes, on your HP Laserjet II or III printer or compatible.
- X
- XYou may want to adapt this to print your return address, as shown
- Xin the commented-out example.
- XYou may have to adjust the X-Y coordinates if your envelopes are
- Xnon-standard (or you don't like where I put things!)
- X
- XIn order for the barcode stuff to function properly, the last address
- Xline must end in a zip code, either 5 digits or (zip+4 format)
- X5 digits, a dash, and 4 digits. Well, ok, I don't check specifically
- Xfor that format, but am looking for the end of the last line, minus
- Xwhite space, to consist of 5 to 10 dashes and/or digits. It is up
- Xto you to provide the garbage-in in the right format for me to
- Xgenerate the right garbage-out.
- X
- XThe barcode portion of this perl script was inspired by a recent posting
- Xto alt.sources:
- X
- X From: todd@toolz.uucp (Todd Merriman)
- X Newsgroups: alt.sources
- X Subject: Generate postal barcodes on HPLJ
- X Message-ID: <1991Aug13.220925.28106@toolz.uucp>
- X Date: 13 Aug 91 22:09:25 GMT
- X Organization: Software Toolz, Inc.
- X
- XTodd wrote a C program to generate the barcodes only, and mentioned
- Xhow useful it would be to any U.S.P.S. mail program:
- X
- X barcode.c
- X
- X This is a program to produce postal barcodes on an HPLJ. It was
- X printed in the Winter '90 issue of the C Gazette (a fine publication).
- X For a complete technical description, see that issue of the magazine.
- X
- X This code could probable be easily adapted to almost any mailing
- X list manager, as it accepts the zip code digits in ASCII and outputs
- X the required HPLJ graphics commands to product a properly formatted
- X postal bar code.
- X
- XDave Buck Caveats:
- XI haven't read the article mentioned by Todd, and only attempted to verify
- Xthe implementation by visual comparison to the barcodes I've actually seen
- Xadded by the U.S.P.S. themselves on three commercial envelopes I received
- Xin yesterday's mail. So you KNOW what the warranty's worth on this one.
- X
- X
- X {aeras,amdahl,ames,daver,netcomsv,sun,zygot}!dlb!dave
- XD. L. Buck and Associates, Inc.; San Jose, California 95119; (408)972-2825
- X
- XAndy Rabagliati ported this to PostScript. I corrected a bug on the
- Xcheck digit calculation. I use labels, as my printer seals envelopes
- Xput through it !! You may have to twiddle the PostScript stuff if you
- Xwant envelopes. I hope I have made this easy.
- X
- XI stuck in the #ifdef conditional stuff, and you will notice that the
- Xscript invocation includes a -P option - this is so Perl runs it all
- Xthrough the PreProcessor to get the HP or PostScript version.
- X
- XEnjoy, Andy.
- END_OF_FILE
- if test 2670 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'env.pl' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'env.pl'\"
- else
- echo shar: Extracting \"'env.pl'\" \(5916 characters\)
- sed "s/^X//" >'env.pl' <<'END_OF_FILE'
- X#!/usr/local/bin/perl -P
- X # Envelope Label Addresser tool, Perl script.
- X # Given an address, either from stdin or a file argument,
- X # addresses a commercial envelope label, including generating postal
- X # bar codes.
- X # I couldn't put envelopes thru my printer without them being sealed!!
- X #
- X # You may want to adapt this to print your return address, as shown
- X # in the commented-out example. (HP only)
- X # You may have to adjust the X-Y coordinates if your envelopes are
- X # non-standard (or you don't like where I put things!)
- X #
- X # In order for the barcode stuff to function properly, the last address
- X # line must end in a zip code, either 5 digits or (zip+4 format)
- X # 5 digits, a dash, and 4 digits. Well, ok, I don't check specifically
- X # for that format, but am looking for the end of the last line, minus
- X # white space, to consist of 5 to 10 dashes and/or digits. It is up
- X # to you to provide the garbage-in in the right format for me to
- X # generate the right garbage-out.
- X
- X # credits :-
- X
- X # todd@toolz.uucp (Todd Merriman) for barcode stuff
- X # He credits :- the Winter '90 issue of the C Gazette
- X # Dave Buck {aeras,amdahl,ames,daver,netcomsv,sun,zygot}!dlb!dave
- X # for original Perl port to HP LaserJet
- X # Andy Rabagliati (andyr@wizzy.com) - who hacked the above to PostScript,
- X # and changed the checkdigit stuff, as I think there was a bug
- X
- X # ---- CONFIGURATION ----
- X
- X # stick #define PS or HP here
- X
- X#ifndef PS
- X#ifndef HP
- Xprint <<"EndOfNoConfig";
- XHP / PostScript label / envelope printer
- XPlease state which configuration you want by putting
- X '#define HP' or
- X '#define PS' in the CONFIGURATION section of script.
- XEndOfNoConfig
- Xexit(1);
- X#endif
- X#endif
- X
- X#ifdef PS
- X$font = "NewCenturySchlbk-Bold"; # font of choice
- X
- X # depending on the size of labels / letters, you need to move
- X # the user origin to the bottom left corner of the area we are
- X # working with. A rotate comes in handy too, sometimes.
- X
- X$xorigin = 0; $yorigin = 684; # x,y origin
- X # this is my origin for labels printed
- X # in a letter printer, sure to need changing
- X
- X$rotate = 0; # rotate ? You might want +-90
- X
- X$barcode_x = 290;
- X$barcode_y = 10; # this is 100ths of an inch from origin
- X
- X#endif
- X
- X # open (out,"|lp"); # Change this to how you like to get
- X # select(out); # to your printer
- X
- X # ------ END OF CONFIGURATION -----
- X
- X#ifdef PS
- Xprint "%! Hey, we talk PostScript\n";
- X
- Xprint "$xorigin $yorigin translate $rotate rotate\n";
- Xprint "/$font findfont 12 scalefont setfont\n";
- X#endif
- X
- X#ifdef HP
- X
- Xprint "\033&l81a3h1O"; # Comm. Envelope, Manual Env. Feed, Landscape
- Xprint "\033(s1p12v0s0b4101T";
- X # Prop., 12 pts, no slant, no bold, CG Times
- X # Here's a dandy place to put your return address, if you want to
- X # use blank commercial envelopes, e.g. ...
- X # print "\033&a4L"; # L Mgin .4", (top 1/2")
- X # print "International Foobs, Ltd.\r\nPOBox 000\r\nArmpit, Wyoming 54321\r\n";
- X # Position for Addressee
- Xprint "\033&a70L\033*p500Y";
- X # L Mgin 3 1/2", (top 1/2"), vert posn 500 d
- X
- X#endif
- X
- X#ifdef PS
- X$y = 80; # start position
- X#endif
- X
- Xwhile (<>) { # Get address from stdin or file arg.
- X#ifdef PS
- X print "10 $y moveto ($_) show\n";
- X $y -= 13; # next line down
- X#endif
- X#ifdef HP
- X print "\r", $_;
- X#endif
- X $zipline = $_; # save last address line for possible zip
- X}
- X
- X$_ = $zipline;
- Xs/\s*$//; # scrub white space at end
- Xif (/[-0-9]{5,10}$/) { # Does this look like a zip, 5 or 5-4?
- X $_ = $&; # get 5 to 9 digit zip, optional dash
- X s/-//; # delete '-' for zip+4 codes
- X # compute check digit: 10 - (mod 10 sum of all digits)
- X
- X $digits = $_;
- X while(length($digits)) {
- X $ckdigit += chop($digits); # sum all digits
- X }
- X $ckdigit = (100 - $ckdigit) % 10; # 10 - (mod 10 of sum)
- X $_ = 'L' . $_ . $ckdigit . 'L'; # long line start and stop markers
- X
- X s/0/LLSSS/g; # postal bar codes for each digit
- X s/1/SSSLL/g;
- X s/2/SSLSL/g;
- X s/3/SSLLS/g;
- X s/4/SLSSL/g;
- X s/5/SLSLS/g;
- X s/6/SLLSS/g;
- X s/7/LSSSL/g;
- X s/8/LSSLS/g;
- X s/9/LSLSS/g;
- X#ifdef PS
- X # Now output the graphic commands for the postal bar code
- X
- X # scale to 1/100 ths of an inch
- X # Bar width .015" to .025", we choose .02"
- X print "0.72 dup scale 2 setlinewidth\n";
- X
- X # Short: .04" to .06", we choose .05"
- X print "/short { 0 5 rlineto stroke } def\n";
- X
- X # Long: .115" to .135", we choose .12"
- X print "/long { 0 12 rlineto stroke } def\n";
- X
- X # chopping here - which means from last to first.
- X # so we move LEFT after each bar, having started right
- X
- X $x = $barcode_x; $y = $barcode_y; # move to bottom right of label
- X
- X
- X while ($_) { # process each Short/Long line indicator
- X $d = chop;
- X ($d eq 'S') && print "$x $y moveto short\n";
- X ($d eq 'L') && print "$x $y moveto long\n";
- X
- X # Go left .045 to .05", we choose .05"
- X $x -= 5;
- X }
- X#endif
- X#ifdef HP
- X # Left edge of barcode 4" from right edge of envelope
- X # Base of barcode .2" from bottom edge of envelope
- X print "\033*p990y1575X"; # vert posn 990 d, hor posn 1575 d
- X print "\033*c6A"; # Bar width .015" to .025", we choose .02"
- X
- X # chop is cheap, and takes last char off of string, too bad you
- X # can't as easily chop from the beginning. So we reverse the
- X # string, and chop from the end.
- X
- X $_ = reverse($_);
- X while ($_) { # process each Short/Long line indicator
- X $d = chop;
- X if ($d eq 'S') {
- X # Short: .04" to .06", we choose .05"
- X # move down, draw down, move back up
- X print "\033*p+21Y\033*c15b0P\033*p-21Y";
- X } else {
- X # Long: .115" to .135", we choose .12"
- X # draw down
- X print "\033*c36b0P";
- X }
- X print "\033*p+15X";
- X # Go right .045 to .05", we choose .05"
- X }
- X
- X#endif
- X}
- X#ifdef PS
- Xprint "showpage\n";
- X#endif
- X
- X#ifdef HP
- Xprint "\033E";
- X#endif
- END_OF_FILE
- if test 5916 -ne `wc -c <'env.pl'`; then
- echo shar: \"'env.pl'\" unpacked with wrong size!
- fi
- chmod +x 'env.pl'
- # end of 'env.pl'
- fi
- echo shar: End of shell archive.
- exit 0
-
-
-
- exit 0 # Just in case...
-