L
luser-ex-troll
Has this already been done better?
Surely this idea isn't new?
This is a project for my mom, for whom
MSWord and Excel no longer play nicely together.
-- luser-ex-troll
#!/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
Surely this idea isn't new?
This is a project for my mom, for whom
MSWord and Excel no longer play nicely together.
-- luser-ex-troll
#!/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