I would like to print the content of the txt file opened in a window of the program. Could anybody help me ? 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.
open(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;
or use the module
#!/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;