> From [EMAIL PROTECTED] Mon Mar  3 03:16:57 2003
> Date: Mon, 3 Mar 2003 11:17:58 +0100 (CET)
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: LPRng: printing to file
>
> Dear experts,
>   could somebody advise me on how to configure a printer that would print
> to file instead to a specified device ? The reason is that OpenOffice
> doesn't support saving to PS or PDF file, so I guess configuring a special
> printer that would just save the PS output to a file would solve the
> problem.
>
> Thanks a lot for help,
>
> best regards
>
>            Tomas
>
>  E-mail : [EMAIL PROTECTED],
>         [EMAIL PROTECTED]

file:
        :sd=/var/spool/lpd/%P
        :filter=/usr/local/libexec/print_to_file

and print_to_file is:

*** this is from LPRng/UTILS/decode_args_in_perl...

#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;
            # this emulates #! processing on NIH machines.
            # (remove #! line above if indigestible)

use Getopt::Std;
my(%args,%options);
# get the arguments
getopts(
        "a:b:cd:e:f:g:h:i:j:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:" .
        "A:B:C:D:E:F:G:H:I:J:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:",
        \%args );

# Now handle options
# set :key=value  -> $option{$key}=$value
# set :key@       -> $option{$key}="0"
# set :key        -> $option{$key}="1"

 map {
        if( m/^\s*:([^=]+)=(.*)/ ){
     $options{$1}=$2;
        } elsif( m/^\s*:([^=]+)[EMAIL PROTECTED]/ ){
         $options{$1}="0";
    } elsif( m/^\s*:([^=]+)/ ){
         $options{$1}="1";
    } elsif( m/^\s*([^|]+)/ ){
         $options{"Printer"}=$1;
        }
 } split( "\n", $ENV{'PRINTCAP_ENTRY'});

# get the control file entries

 map {
        if( m/^\s*([A-Z])(.*)/ ){
     $options{$1}=$2;
        } elsif( m/^\s*([a-z])/ ){
         $options{'Format'}=$1;
        }
 } split( "\n", $ENV{'CONTROL'});


**** and now you can actually use them...
use FileHandle;
use File::Temp qw( :mktemp );

my($buffer);
my($fh,$filename) = mkstemp( "/tmp/lpr_XXXXXX" );
print  STDOUT "Printing job $args{n}\n to $filename\n";
while( sysread(STDIN, $buffer, 1024 ) ){
        syswrite( $fh, $buffer );
}

Note: note the use of mktemp.  It is DANGEROUS to blindly write
to a known file,  as all sorts of security loopholes are opened if you do.

Patrick Powell                 Astart Technologies
[EMAIL PROTECTED]            6741 Convoy Court
Network and System             San Diego, CA 92111
  Consulting                   858-874-6543 FAX 858-751-2435
LPRng - Print Spooler (http://www.lprng.com)

-----------------------------------------------------------------------------
YOU MUST BE A LIST MEMBER IN ORDER TO POST TO THE LPRNG MAILING LIST
The address you post from MUST be your subscription address

If you need help, send email to [EMAIL PROTECTED] (or lprng-requests
or lprng-digest-requests) with the word 'help' in the body.  For the impatient,
to subscribe to a list with name LIST,  send mail to [EMAIL PROTECTED]
with:                           | example:
subscribe LIST <mailaddr>       |  subscribe lprng-digest [EMAIL PROTECTED]
unsubscribe LIST <mailaddr>     |  unsubscribe lprng [EMAIL PROTECTED]

If you have major problems,  send email to [EMAIL PROTECTED] with the word
LPRNGLIST in the SUBJECT line.
-----------------------------------------------------------------------------

Reply via email to