in reply to Re^2: Printing Labels
in thread Printing Labels
Sure, here you go. In my defence, this was written 20 years ago ;-)
#!/usr/bin/perl use strict; use warnings; my ($ll, $numadd, @add); my @labpos = (2, 3, 6, 8, 7, 5, 4, 1); print "How many addresses? "; chomp ($numadd = <>); die 'Bad data' if ($numadd !~ /^[0-9]+$/); print "How many labels left? "; chomp ($ll = <>); die 'Bad data' if ($ll !~ /^[0-9]+$/); my $text = '\documentclass[10pt]{article} \usepackage{epsf} % was 23mm \setlength{\oddsidemargin}{-20.5mm} \setlength{\textwidth}{201.7mm} \setlength{\topmargin}{-24.5mm} \setlength{\textheight}{278mm} \setlength{\parindent}{0pt} \setlength{\parskip}{0pt} \pagestyle{empty} \begin{document} \setlength{\unitlength}{1mm} \begin{picture}(99.1,67.7) %%addlab1%% \end{picture}% \hspace{3.5mm}% \begin{picture}(99.1,67.7) %%addlab2%% \end{picture} \begin{picture}(99.1,67.7) %%addlab3%% \end{picture}% \hspace{3.5mm}% \begin{picture}(99.1,67.7) %%addlab4%% \end{picture} \begin{picture}(99.1,67.7) %%addlab5%% \end{picture}% \hspace{3.5mm}% \begin{picture}(99.1,67.7) %%addlab6%% \end{picture} \begin{picture}(99.1,67.7) %%addlab7%% \end{picture}% \hspace{3.5mm}% \begin{picture}(99.1,67.7) %%addlab8%% \end{picture} \end{document}'; my $this = ' \put(5,40){\parbox{80mm}{\Large \bf % was Large %%addr%% }} \epsfxsize=15mm \put(81,47){\epsfbox{logo.eps}} \put(3,7){\scriptsize \sf If undelivered, please return to:} \put(3,4){\scriptsize \sf Hippo Enterprises PLC, PO Box 999, Ungulatesville, XL99 9XL} '; for my $i (0 .. $numadd - 1) { $add[$i] = ''; print "Enter address $i (terminate with .)\n"; while ($_ = <>) { last if /^\./; $add[$i] .= $_; } $_ = $this; $_ =~ s/%%addr%%/$add[$i]/; $text =~ s/%\%addlab$labpos[8-$ll+$i]%%/$_/; } open OUT, '>address.tex' or die 'Cannot open outfile'; print OUT $text; close OUT; system ('make');
And the Makefile is just the standard
go: address.ps gv address.ps address.ps: address.dvi dvips -o address.ps address.dvi address.dvi: address.tex latex address.tex
When entering the addresses, they will need to include the \\ for LaTeX line breaks. Add your own code for this in the Perl if you want that handled by the script instead.
Why the Makefile? Well, occasionally something happens which the preview shows to be a problem. Most often you can simply manually edit address.tex and re-run the make command from the shell rather than re-processing the whole thing from scratch. YMMV.
In case it isn't clear, the "How many labels left?" prompt is referring to the number of unused labels remaining on the sheet of 8. Since you're also wondering what @labpos is all about, that's because if you just use up a few labels on a sheet in the normal order of left-to-right, top-to-bottom, the label sheets we use are thin enough once the labels have peeled off the backing that the printer starts having problems feeding them through. Thus my engineered fix is to use them up in a staggered/chequered pattern.
If anyone did want to turn this into a web-based system, it would be easy enough. But then there would really be no point to the Makefile.
Hope this is useful to somebody.
🦛
|
|---|