Skip to content

Efficient printing of USPS shipping labels

by Layne on May 3, 2011

When you use the online USPS shipping label generator (we use it via paypal), it generates a full page of information. The top half of the page is the label you affix to the package, and the other half is full of extra info that isn’t needed for the shipping label. If you want to use full-page label sheets, you really don’t want to waste half the page each time you print a label. To work around this, we developed a script to split a PDF into top- and bottom-half PDFs, enabling you to only print the top half (the actual label) while leaving the bottom half of the label page usable for the next label you print.

For example, here’s a slightly-doctored image of the original printing label. I have highlighted the actual label, and darkened out everything else:

The script below is used to split that PDF document into two smaller documents, one each for the upper and lower half. We have only tested it on Linux, but it might work on windows or Mac OS if you have the right tools installed (ghostscript).

#!/bin/bash
# A script used to split USPS shipping labels into two pages,
# so you can print the label without wasting the other half.
# Written by Matthew Beckler, for Wayne and Layne, LLC
# wayneandlayne at wayneandlayne dot com
# Last Updated: January 23, 2011
#
# This is what GS told me the original PDF size was
# Page 1 MediaBox: [ 612 792 ]
# Output produced from this command:
# gs -dNODISPLAY -q -sFile=input.pdf -dDumpMediaSizes \
# -dDumpFontsUsed -dShowEmbeddedFonts pdf_info.ps
# which uses the file "pdf_info.ps" from the GS source code.

BASENAME=`basename "$1" .pdf`

gs -o "${BASENAME}_label.pdf" -sDEVICE=pdfwrite -g6120x3960 -c \
"<</PageOffset [0 -399]>> setpagedevice" -f "$1"

gs -o "${BASENAME}_info.pdf" -sDEVICE=pdfwrite -g6120x3960 -c \
"<</pageOffset [0 0]>> setpagedevice" -f "$1"

You can easily use this script to split a PDF into two halves by passing in the name of the PDF document as the first and only argument:

./split_usps_shipping_label.sh shipping.pdf

The script will create two files: shipping_label.pdf and shipping_info.pdf (it’s based on the name of the file you specified).shipping_label.pdf will be a half page containing only the upper-half of the original document, and can be directly printed without wasting the other half of the full-page label.

From → Uncategorized

3 Comments Leave one →
  1. Martin permalink

    paypal -> profile -> more options -> my selling tools -> shipping preferences -> update -> usps edit printer settings -> uncheck “print receipt”

    saves you all that extra trouble.

  2. Martin, Thanks for the info. I hadn’t ever noticed all those settings hiding in my paypal profile. Next time I need a shipping label, I’ll have to see how the “print receipt” affects the label. Thanks!

Trackbacks and Pingbacks

  1. Efficient printing of USPS shipping labels « adafruit industries blog

Leave a Reply

Note: HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS