Loading ...
Sorry, an error occurred while loading the content.

Re: The filter for printer just doesn't work --help needed

Expand Messages
  • vinay
    Never mind, I went the CUPS way and all is fine now. Its hard with out documentations.. my previous admin should have done that Best, vinay. ... error ...
    Message 1 of 2 , Sep 19, 2007
    • 0 Attachment
      Never mind, I went the CUPS way and all is fine now. Its hard with out
      documentations.. my previous admin should have done that

      Best,
      vinay.
      --- In LINUX_Newbies@yahoogroups.com, "vinay" <kahinoie@...> wrote:
      >
      > Hi Folks,
      >
      > I have a big problem here. I am fairly new to writing print filters so
      > I am trying to use the one my previous admin had written. A web
      > application deployed on the linux server uses the details given by
      > this filter to display the values on the web page. While it was
      > working on the older machine, I just wanted to transfer entire setup
      > to a better machine and did so. What I observed is, in the printcap
      > file, if I remove the line related to the filter, I can do the remote
      > printing else the filter somehow is failing to do its job and thus the
      > jobs are not getting listed in lpq as well as web interface. But since
      > we need this filter to display the values, deleting the line is not an
      > option. Here is the printcap file:
      >
      > ##LPRNGTOOL## REMOTE
      > lj1200
      > :sd=/var/spool/lpd/lj1200
      > :sh
      > :mx=0
      > :af=/var/spool/lpd/lj1200/acct
      > :ml=0
      > :lf=/var/spool/lpd/lj1200/log
      > :cd=/var/spool/lpd/lj1200/
      > :filter=/var/spool/lpd/filter.pl
      > :lp=lpx@localhost
      > :server
      > :
      >
      > ##LPRNGTOOL## LOCAL
      > lpx
      > :sd=/var/spool/lpd/lpx
      > :sh
      > :mx=0
      > :af=/var/spool/lpd/lpx/acct
      > :ml=0
      > :lf=/var/spool/lpd/lpx/log
      > :cd=/var/spool/lpd/lpx/
      > :lp=/dev/usb/lp0
      > :
      >
      >
      >
      >
      >
      >
      >
      > And here is the filter.pl that the previous admin wrote:
      >
      >
      >
      > #!/usr/bin/perl
      >
      > # HISTORY
      >
      > # Feb 2005:
      > # - Changed table scheme for the FLMCSS system
      > #
      > # April 2003:
      > # - Added support for pdf files format
      > # - Added support to handle layouts (2 pages per sheet) reduction
      >
      > use strict;
      > use Getopt::Std;
      > use POSIX;
      > use DBI;
      >
      > # -------------------------- CONSTANTS -------------------------------
      > # Script exit status values
      > my($RET_JSUCC, $RET_JFAIL, $RET_JABORT, $RET_JREMOVE, $RET_JHOLD);
      > $RET_JSUCC = 0;
      > $RET_JFAIL = 1;
      > $RET_JABORT = 2;
      > $RET_JREMOVE = 3;
      > $RET_JHOLD = 6;
      >
      > # MySQL connection info
      > my $serverName = "127.0.0.1";
      > my $serverPort = "3306";
      > my $serverUser = "flmc";
      > my $serverPass = "flmc579";
      > my $serverDb = "flmcDS";
      > my $serverTabl = "printjob";
      >
      > # Misc
      > my $CANNOT_PRINT_TITLE="CANNOT PRINT THIS FILE: ";
      > my $SUBMIT2DB = 1;
      > my $ECONOMODE = "OFF";
      >
      > # -------------------------- GLOBAL VARS -----------------------------
      > my(%args);
      >
      > # Get the parameters passed by lpd and they are the following:
      > # -D = date and time
      > # -J = job name
      > # -H = host name
      > # -e = data file name
      > # -d = path to the spool
      > # -n = user name
      > # -j = job id
      > # -k = config file name
      >
      > #print STDERR "ARGUMENTS: ";
      > #foreach my $item (@ARGV) {
      > # print STDERR "$item, ";
      > #}
      >
      > getopts('A:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:'
      > . 'a:b:cd:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z:',\%args);
      >
      > #DEBUG the parameters
      > #foreach my $item (keys(%args)) {
      > #print STDERR "[$item] = ".$args{"$item"}."\n";
      > #}
      >
      > # ------------------------ FUNCTION SECTION ---------------------------
      > sub exitWithError($) {
      > print STDERR "$_[0]";
      > exit $RET_JREMOVE;
      > }
      >
      > # Prints a PCL control header for printjob.
      > # The parameter is whether you want HQ or not (0, 1)
      > sub printPclHeader() {
      > print STDOUT "\c[\%\-12345X\@PJL JOB\n\@PJL SET RESOLUTION =
      > 600\n\@PJL SET ECONOMODE = ";
      > print STDOUT "$ECONOMODE\n";
      > print STDOUT "\@PJL ENTER LANGUAGE = POSTSCRIPT\n";
      > }
      >
      > sub printPclTrailer {
      > print STDOUT "\cD\c[\%\-12345X\@PJL EOJ\n\@PJL ECHO EOJ";
      > }
      >
      > sub getNumPagesFromPS() {
      > my($ipages, $icopies);
      > my($sline);
      > $ipages=0;
      > $icopies=1;
      > # DEBUG print("Opening $_[0]\n");
      > # open(IFILE, "< $_[0]") || exitWithError("Counld not open datafile:
      > $_[0], $!");
      >
      > my $isps = 0;
      > my $isps_with_pcl = 0;
      > my $counter = 1;
      > my $igroups = 0;
      > my $icurpage = 1;
      > my $iwin98_copies = 0;
      >
      > $sline = <STDIN>;
      > if ($sline =~ /^\%\!PS-Adobe-*/) { # It's pure POSTSCRIPT. It needs
      > header
      > printPclHeader();
      > print STDOUT $sline;
      > $isps = 1;
      > }
      > elsif ($sline =~ /\%\-12345X\@PJL JOB/) { # It's in PCL format
      > print STDOUT $sline;
      > while (($sline = <STDIN>) && ($sline =~ /^\@PJL/)) {
      > if ($sline =~ /ECONOMODE/) {
      > print STDOUT "\@PJL SET ECONOMODE = $ECONOMODE\n";
      > }
      > else {
      > print STDOUT $sline;
      > }
      > if ($sline =~ /POSTSCRIPT/) {
      > $isps_with_pcl = 1;
      > }
      > }
      > if ($isps_with_pcl == 0) {
      > exitWithError("Cannot print nonPostscript file");
      > }
      > }
      > else { # Non postscript and non PCL...
      > exitWithError("Undeterminable format, print failed");
      > }
      >
      > # DEBUG print("The count is $counter\n");
      >
      > LOOP_FINDSETUP: while ($sline = <STDIN>) {
      > print STDOUT $sline;
      > last LOOP_FINDSETUP if ($sline =~ /^\%\%BeginSetup/); # Freaking
      > weird syntax...
      > }
      >
      > LOOP_FINDCOPIES: while ($sline = <STDIN>) {
      > print STDOUT $sline;
      > if ($sline =~ /(\/\#copies|NumCopies) (\d+)/) {
      > $icopies = $2 if ($2 > $icopies);
      > }
      > last LOOP_FINDCOPIES if ($sline =~ /^\%\%EndSetup/);
      > }
      >
      > LOOP_FINDGROUP: while ($sline = <STDIN>) {
      > print STDOUT $sline;
      > if ($sline =~ /^\%\%Page: (\d+)/) {
      > $icurpage = $1;
      > LOOP_BEGINPAGESETUP: while ($sline = <STDIN>) {
      > print STDOUT $sline;
      > last LOOP_BEGINPAGESETUP if ($sline =~ /^\%\%BeginPageSetup/);
      > }
      >
      > LOOP_PAGESETUP: while ($sline = <STDIN>) {
      > print STDOUT $sline;
      > # Keep track of a damn copies flag for single page for win98 postscript
      > if ($sline =~ /^\[\{(\d+)/) {
      > sleep 5;
      > $iwin98_copies = -1 * $1;
      > }
      > if ($sline =~ /#copies/) {
      > sleep 5;
      > $iwin98_copies = -1 * $iwin98_copies;
      > }
      > last LOOP_FINDGROUP if ($igroups == 0 && $icurpage != 1); # Stop
      > looking for group info
      > if ($sline =~ /startnup/) {
      > if ($icurpage == 1) {
      > $igroups = 1; # Mark the beginning of the group count
      > }
      > else {
      > $igroups = $icurpage - $igroups; # Get the groups per page
      > last LOOP_FINDGROUP;
      > }
      > }
      > last LOOP_PAGESETUP if ($sline =~ /^\%\%EndPageSetup/);
      > }
      > }
      > }
      >
      > LOOP_FINDTRAILER: while ($sline = <STDIN>) {
      > print STDOUT $sline;
      > if ($sline =~ /^\%\%Page: (\d+)/) {
      > $icurpage = $1;
      > }
      > last LOOP_FINDTRAILER if ($sline =~ /^\%\%Trailer/);
      > }
      >
      > LOOP_FINDAPAGES: while ($sline = <STDIN>) {
      > print STDOUT $sline;
      > if ($sline =~ /^\%\%Pages: (\d+)/) {
      > $ipages = $1;
      > }
      > }
      >
      > if ($isps == 1) { # For pure PostScript, print the PCL Trailer
      > printPclTrailer();
      > }
      >
      > $ipages = $icurpage unless ($ipages != 0); # If there is no Pages:
      > keyword then use the last page number
      > if ($igroups == 0) {
      > $igroups = 1;
      > }
      > elsif ($igroups == 1) {
      > $igroups = $icurpage;
      > }
      >
      > if ($ipages == 1 && $iwin98_copies > 0) { # Handle win98 1 page
      > multiple copies problem
      > $icopies = $iwin98_copies;
      > }
      >
      > my $itotal = ceil($ipages / $igroups) * $icopies;
      >
      > if ($SUBMIT2DB == 0) {
      > print "=================
      > PAGES: $ipages
      > GROUPS: $igroups pages per sheet
      > COPIES: $icopies
      > TOTAL: $itotal
      > =================\n";
      > }
      > return $itotal;
      > }
      >
      > my($ipages);
      >
      > #if (!exists($args{'e'})) {
      > # print("No file\n");
      > # exit $RET_JABORT;
      > #}
      >
      > # ------------------------ MAIN SECTION ---------------------------
      > #$ipages = getNumPagesFromPS((exists($args{'d'})? ($args{'d'}."\/") :
      > "") ."$args{'e'}");
      > $ipages = getNumPagesFromPS();
      > my ($printable,$jobtitle);
      > if ($ipages < 1) { # If not PS or could not read page numbers print
      error
      > $printable = 0;
      > $jobtitle = $CANNOT_PRINT_TITLE . $args{'J'};
      > } else {
      > $printable = 1;
      > $jobtitle = $args{'J'};
      > }
      >
      > if ($SUBMIT2DB) {
      > my $stimestp = $args{'D'};
      > $stimestp =~ s/\-|:|\.\d+$//g; # Remove the -,: and the .###
      > miliseconds.
      > $args{'n'} = uc($args{'n'});
      >
      > my $dbh =
      >
      DBI->connect("DBI:mysql:database=$serverDb;host=$serverName;port=$serverPort",$serverUser,$serverPass);
      > my $statement = "INSERT INTO $serverTabl
      > (job_id,host,user,title,pages,time,status) VALUES";
      > $statement .=
      >
      qq(("$args{'A'}","$args{'H'}","$args{'n'}","$jobtitle",$ipages,$stimestp,$printable));
      > my $success = $dbh->do($statement);
      > $dbh->disconnect;
      > }
      > exit $RET_JSUCC;
      >
      >
      >
      >
      > Any pointers?
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.