in reply to Re: Printing Labels
in thread Printing Labels

Publish the script here? Though in a perfect world for Bod's application, it would be standalone so it could run off a web server for remote people to download/print.

I hope that such remote access would be suitably secure, since it's got people's PII in it!

Replies are listed 'Best First'.
Re^3: Printing Labels
by hippo (Archbishop) on Oct 09, 2024 at 09:16 UTC

    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.


    🦛

Data Security (was: Re^3: Printing Labels)
by Bod (Parson) on Oct 08, 2024 at 21:14 UTC
    I hope that such remote access would be suitably secure, since it's got people's PII in it!

    Yes...most definitely...

    The "remote people" are directors and employees with their own login and 2FA. The scripts to access the database reside above the webroot and all database calls are sanitised *. Plus, everyone accessing has undergone data protection training. We take data security seriously.

    We have also started regularly penetration testing an environment that we've created for this purpose. The code is identical to our production site except that notification emails are turned off and we connect to the production database with an account with only SELECT permissions. We use ZAP for penetration testing.

    * I'm looking forward to the talk from LanX on this topic as we might be able to do even better.