in reply to Perl tk - open file and print content
I would like to print the content of the txt file opened in a window of the program. Could anybody help me ?
I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh
Do you just want to print from the filename itself? Or do you want to open the file in an editor to see it, before you print it? In either case, you probably would use the same code in the callbacks. For MS Windows I would use a Windows only module, but on Linux you can use Net::CUPS::Printer, or use a forked system call to run the lpr command. You could also print directly to the printer, if you wanted more control.
or use the moduleopen(LPR, "|lpr -Plp0 >/dev/null 2>&1"); open (FILE,"< $0 ") or die "Couldn't open: $!"; my $text = do {local $/; <FILE>}; close FILE; print LPR $text; close LPR;
#!/usr/bin/perl use warnings; use strict; use Net::CUPS::Printer; use Data::Dumper; my @printers = cupsGetPrinters (); print "printers-> @printers\n"; my $printer = cupsGetDefault(); print "Default printer-> $printer\n"; my %options =(); my $jobid = cupsPrintFile($printer,"./$0",'Job1',\%options); print "jobid-> $jobid\n"; my $jobs = cupsGetJobs('lp0',1,0); print "jobs-> $jobs\n"; print Dumper([$jobs]),"\n"; my $cancel = cupsCancelJob('lp0', $jobid); print "cancel-> $cancel\n"; #my $jobs = cupsGetJobs('lp0',1,0); #print "jobs-> $jobs\n"; #print Dumper([$jobs]),"\n"; my $user = cupsUser(); print "user-> $user\n"; exit;
I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl tk - open file and print content
by Giorgio C (Novice) on Jan 18, 2012 at 16:03 UTC | |
by zentara (Archbishop) on Jan 19, 2012 at 10:42 UTC | |
by Giorgio C (Novice) on Jan 19, 2012 at 14:25 UTC | |
by Anonymous Monk on Jan 19, 2012 at 14:30 UTC | |
by zentara (Archbishop) on Jan 19, 2012 at 16:54 UTC | |
by Giorgio C (Novice) on Jan 20, 2012 at 10:58 UTC | |
| |
Re^2: Perl tk - open file and print content
by Anonymous Monk on Jan 16, 2012 at 15:13 UTC | |
by Giorgio C (Novice) on Jan 18, 2012 at 15:10 UTC |
In Section
Seekers of Perl Wisdom