Created
August 2, 2014 10:11
-
-
Save luser-dr00g/79dc83d4e2b133a67eee to your computer and use it in GitHub Desktop.
perl/postscript csv->avery labels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# labels.pl reads csv records in the form: | |
# "Name","123 Street","Apt","City, ST ZIP" | |
# from a file named "addr.csv" and | |
# produces a postscript program on stdout | |
# suitable for piping into ps2pdf or | |
# even distiller, maybe | |
# CAVEATS: prototype produces at most | |
# one page. label and sheet sizes are hard-coded | |
# at 3 3-inch-width labels which are 4*17 points | |
# high. I don't have any real ones on hand | |
# to measure. | |
$IN = "addr.csv"; | |
open IN or die "Can't open input: $!"; | |
print <<PROLOG; | |
%! | |
/in{72 mul}def | |
/LEAD 17 def | |
/LM 10 def | |
/count 0 def | |
/TM 11 in LEAD sub def | |
/Palatino-Roman 15 selectfont | |
[ | |
PROLOG | |
while(<IN>) { | |
s/\n$//; | |
s/^"/\[\(/; | |
s/","/\)\(/g; | |
s/"$/\)\]/; | |
s/$/\n/; | |
print; | |
} | |
print <<PSPROGRAM; | |
] | |
{ %each record | |
LM TM moveto | |
{ %each address line | |
dup () eq { pop } { % skip empties | |
show % paint the string | |
%currentpoint exch = = = % diagnostic | |
LM currentpoint exch pop LEAD sub moveto % reposition | |
} ifelse | |
} forall | |
/LM LM 3 in add store % move over | |
/count count 1 add store | |
count 3 mod 0 eq { % back to left after each 3 | |
/LM 10 store /TM TM LEAD 4 mul sub store | |
} if | |
} forall | |
showpage | |
PSPROGRAM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment