printing a file to a print server prettily

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I generate a series of paper files every morning, anywhere from a few
dozen to a couple of thousand. I have copied the function that I use
below. This function takes a file name, which is an ASCII file with a
name like 'john_doe.txt' with a number of fields (name, address,
previous college, enrollment date, etc., maybe 30 in all) and the
resulting output is distriubted to personnel for further processing
and filing (in a physical file folder -- which is one reason why we
need to actually print the file).

We have an employee who has been used to getting output from an Access
database. The field names are printed in italic, the values are
printed in san-serif, and the values have nice little boxes drawn
around them. She has convinced everyone that they all need pretty
output rather than a plain ASCII output.

So ... I'm sitting here wondering how I can convince the printer to
print some part in italics, some part in sans-serif, and draw pretty
boxes. Any ideas?

Thanks, CC.

use File::Copy;
sub print_file
     $print_file = shift;
     $print_test = copy($print_file, '//serprintserver/SERITS') or
warn "could not print, $!";
     if ($print_test == 1)
         print "Printed $print_file\n";
         unlink $print_file;

Re: printing a file to a print server prettily

Quoted text here. Click to load it

You need to create a document in a format that supports those elements,
e.g. PS or DVI or HTML or PDF or RTF or DOC or DOCX or any of many
others, and is understood by your printer or can be converted by a
printer driver into a format that is understood by your printer.


Re: printing a file to a print server prettily

Quoted text here. Click to load it

Thanks. After looking at PDF and RTF, I got RTF-Writer (because it
looked a lot simpler) and have created bunches and bunches of RTF

Unfortunately, the files are not printing. We have several categories,
New, Update, Change, etc., and I modified the New files to 'rtf'. Now,
the 'txt' file print just like they did before, but the rtf files are
not printing. You note that the function unlinks the file after
printing. The print message is appearing, but the rtf files are not
coming out of the printer, and  the files are not being deleted. This
is curious because either the print message appears and the files are
deleted, or the error message prints and the files are not deleted. I
get the print message but the files are not deleted.

It's not a Perl problem, I don't think. I'm not asking for help, just
complaining. It's 4:35 p.m. on a Friday afternoon, and I'm looking at
coming in tomorrow, so if you can think of anything off the top of
your head, please buzz me.

Thanks, CC.

Re: printing a file to a print server prettily

Quoted text here. Click to load it

I have read your response to Jurgen as well. I feel your pain ;-)

Quoted text here. Click to load it

What language does the printer speak? There are, by an large,
two alternatives:

1) The printer speaks Postscript

a) In this case, you can probably insert POD directives in the file
and use pod2ps before sending it to the printer.

b) Use HTML::Template or any other templating module to fill
in a LaTeX template. Run latex and dvips to get the file to print.
might be useful here, although I have not used it).

2) The printer speaks PCL. All you really need is PCL 1.
Embed text format switching escape codes in the file. Send file to printer.
Again, a template based approach ought to work here.

The specs are at

Just out of curiosity, I tried the following:


use strict;
use warnings;

use HTML::Template;

my $PRINTER = q;

my $ESC = "3";

my %c = (
     BOLD     => "$(s3B",
    _BOLD     => "$(s0B",
     ITALIC   => "$(s1S",
    _ITALIC   => "$(s0S",

my $tmpl = <<EO_TMPL;
$cName:$c $c<TMPL_VAR NAME>$c

my $ht = HTML::Template->new( scalarref => $tmpl );

$ht->param( RECIPIENTS => [
    { NAME => 'No Nonsense' },
    { NAME => 'The Daily Whatever' },
    { NAME => 'Donald Duck' },

open my $PRN, '>', $PRINTER
    or die "Cannot open '$PRINTER': $!";

print $PRN $ht->output;

close $PRN or die "Cannot close '$PRINTER': $!";


This works fine with my Brother laser printer which understands PCL. (Can
you tell I wrote some dot matrix printer drivers in the 80s ;-)

Anyway, choose the approach that works best for you. Use plain
text for data storage and use a prettified version for the clerks to
put in hanging file folders.

Good luck.


(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW: /

Site Timeline