printing a file to a print server prettily

Discussion in 'Perl Misc' started by ccc31807, Apr 25, 2008.

  1. ccc31807

    ccc31807 Guest

    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;
    }
    }
    ccc31807, Apr 25, 2008
    #1
    1. Advertising

  2. ccc31807 <> wrote:
    >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?


    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.

    jue
    Jürgen Exner, Apr 25, 2008
    #2
    1. Advertising

  3. ccc31807

    ccc31807 Guest

    On Apr 25, 2:28 pm, Jürgen Exner <> wrote:
    > 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.


    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
    files.

    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.
    ccc31807, Apr 25, 2008
    #3
  4. ccc31807 <> wrote in news::

    > 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.


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

    >
    > 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, $!";


    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.
    (http://search.cpan.org/~andrewf/LaTeX-Driver-0.07/lib/LaTeX/Driver.pm
    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 http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13210/bpl13210.pdf

    Just out of curiosity, I tried the following:

    #!/usr/bin/perl

    use strict;
    use warnings;

    use HTML::Template;

    my $PRINTER = q{\\\\AARDVARKVI\\HL2070N};

    my $ESC = "\033";

    my %c = (
    BOLD => "${ESC}(s3B",
    _BOLD => "${ESC}(s0B",
    ITALIC => "${ESC}(s1S",
    _ITALIC => "${ESC}(s0S",
    );

    my $tmpl = <<EO_TMPL;
    <TMPL_LOOP RECIPIENTS>
    $c{BOLD}Name:$c{_BOLD} $c{ITALIC}<TMPL_VAR NAME>$c{_ITALIC}
    </TMPL_LOOP RECIPIENTS>
    EO_TMPL

    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': $!";

    __END__

    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.

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://www.rehabitation.com/clpmisc/
    A. Sinan Unur, Apr 25, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Shaw

    Lock Print Screen and File Print

    Bryan Shaw, Apr 19, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,947
    Kevin Spencer
    Apr 20, 2005
  2. Arun Kumar Srinivasan

    Using javax.print classes to print text/file

    Arun Kumar Srinivasan, Jan 13, 2004, in forum: Java
    Replies:
    5
    Views:
    6,148
    Gregory A. Swarthout
    Jan 14, 2004
  3. keto
    Replies:
    0
    Views:
    931
  4. BrassicaNigra

    Server Printing using Print Dialog

    BrassicaNigra, Jul 9, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    539
    Steven Cheng [MSFT]
    Jul 10, 2008
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    348
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page