Envelope Maker, a Gtk2 frontend to “envelope.pl”



So, I decided that now that I have a proper laser printer I want to be able to print professional envelopes again in Linux. I define a professional envelope as having three parts: return address, to address and the delivery point postnet (that barcode-like thing in the bottom right corner). In reality, printing the delivery point postnet speeds up postal processing by a day since it guarantees no human being has to look at the envelope until it reaches the destination street, and I always am a fan of efficiency.
So, what’s a delivery point postnet? It’s 12 numbers, the 5-digit zip code, the 4 digit +4, the 2 digit delivery point code and one check digit, printed in a height-varying barcode-like symbol on the bottom right corner of an envelope. Those numbers, taken together, indicate a specific mailbox in the United States. Theoretically all you would need to get a letter from A to B would be a delivery point postnet and a return address. I might try that sometime…
Back on track, I decided I wanted to print these things in Linux so I went tracking down free software to do it for me. I found Gregory Spath’s useful perl script called “envelope”, available on his website. It works like a charm - I expended 10 envelopes getting the margin values set right in my ~/.enveloperc file, but from then on it worked like a charm. It even prints postnets in the bottom right corner of the envelope! The only problem with this is that in order to print a full delivery point postnet it requires that I provide said delivery point value, in addition to the zip+4. Well, that’s a pain!
So, armed with the determination of being lazy in the future, I sought out something to locate that delivery point value for me. After several non-starts I realized that the USPS had several tools on their website to provide this value. One of them is even made to be used by programs (it has its web-based API)! Oh, that’s too good to be true, I thought! Indeed it was, the USPS requires a lengthy registration procedure to be permitted to use this API. Luckily, there still is another tool: a web-based query intended to be used by human beings. Unfortunately, programming something to use a web page intended to be used by human beings is generally another serious pain. Fortunately for me I found that Gregor Purdy wrote a perl module called Scrape::USPS::ZipLookup to do just that for just this script. Unfortunately again, it was slightly out of date. Fortunately, I fixed it and have emailed the changes to Mr. Purdy for release.
So that leaves me with a tool that can take a provided address, ask the USPS to correct it and return the full zip+4+delivery point code. What could I do next? Oh, it’s obvious, I wrote a GUI.
So now I have a small Gtk2 frontend to “envelope.pl” which you can see to the right here. It’s fairly simple: the address fields and four buttons. In brief, here’s what they do:
- Fix: Lookup the address with the USPS and fill in / correct fields
- Cancel: Close
- Print Preview: Show a preview of the envelope in GGV, GV or whatever you’ve configured to show postscript
- Print: Print the envelope using LPR
If you notice in the first screenshot I’ve put in a somewhat incomplete address. After pressing the “fix” button the USPS filled in the rest of the information for me, and that’s visible in the second screenshot.
Once that’s done I clicked the Print Preview button and the Gtk GhostScript viewer (GGV) opened to show me vaguely what the envelope would look like once printed. That’s the third screenshot.
Finally, the last screenshot shows the envelope I printed by clicking the Print button.
Not bad for a lazy Sunday morning, eh?
Source is available here: http://downloads.pugsplace.net/tree/envelope-maker-0.1.tar.gz. It contains the updated Scrape::USPS::ZipLookup module and Gregory Spath’s envelope.pl. You’ll have to install Perl-gtk2 and the dependencies for Scrape::USPS::ZipLookup via CPAN, but that’s described in the included INSTALL file.
9 Comments so far
Leave a reply
Nice!
I’ll have to check it out some time. I know that my program is totally file driven, so it is not the best tool for your GUI. Maybe I’ll add some command line stuff to better merge with your tool. My original vision was to send a bunch of files in batch, or, as in my case, just print a bill when needed, leaving those files stored. But, just like you, I now tend to use the tool one address at a time these days.
Anyway,
A nice feature I didn’t see on your web page would be to set some of the .enveloperc options. It shouldn’t be too hard, since my program allows full override using the [options] section of each envelope file.
Nice App!
– Greg, original envelope developer
I thought about converting your script to work without needing a file, necessarily, but time constraints made me just make a frontend. I might redesign it later and add in [Options] settings, but like most OSS stuff, I wrote this to scratch my own itch. If someone makes a request for the options or a tighter rewrite, I’ll add it to my work queue and probably get around to it. It’s always entertaining to hack on perl.
Way cool dude. Maybe one of these days I figure out how to make CUPs work and connect my printer to my linux box and use it as a print server and install this thing. Very nice looking.
pug, i took these for you:
http://flickr.com/photos/schmeebot/156150130/
http://flickr.com/photos/schmeebot/156150131/
thuy
Thuy - dude! Evil Pug! Hehehe!
Trying to get your envelope maker going on FC4 but am stuck with the following message: My limited linux (perl) knowledge says Gtk2 can’t be found… yum says it’s installed but I don’t know how to tell perl (envelope-maker) where it is.
Please excuse my noobie ignorance… I’d appreciate a pointer !!!!
Below is output from some testing I’ve done.
lh envelope-maker]# perl envelope-maker.pl
Can’t locate Gtk2.pm in @INC (@INC contains: /usr/lib/perl5
************ whole bunch of additional stuff
BEGIN failed–compilation aborted at envelope-maker.pl line 20
Use Gtk2; # load the Gtk-Perl module
You need gtk-perl in addition to Gtk. Try running

perl -MCPAN -e 'install Gtk2'as root.Got the first screen from your envelope maker code…. like the one at the top of this page. Looking forward to getting the whole thing working. Have to say that installing envelope-maker is NOT a trivial exercise for a perl/linux noobie. I think the most important part of my success so far was loading everything into the perl directory at /usr/lib/perl5/vendor_perl/5.8.6. I think this solved what I originally thought was pathing problems A major breakthrough was replying NO to the configuration question on the first execution of perl.
Having fun and one more step toward WINXP freedom….
Thanks for your help
Ted in Atlanta
Hey pug,
Just so you know, I released version 1.0.2 of the envelope script. It’s now known as ‘gpep’ (Greg’s practical envelope printer). That’s a nicer name than ‘envelope’
The new version allows input from STDIN, so it should be much easier to mesh with your GUI. I also have fixed the options for placement on feeding, and added the ability to toggle forced manual feed.
Just look for gpep on freshmeat.