counting pages sent to postscript printer via samba and lpd

Olivier Nicole on at
Thu Jun 18 08:25:01 UTC 2009


> I'm busy reading the manual on this, but am wondering if anyone has 
> tips and howtos available.....
> I took delivery of our new color laser printer, a CP1515n, HP 
> networked color laser.  since this thing is not exactly cheap to run 
> I want to count pages per user, and since I have failed miserably to 
> get this right when using PCL drivers, I'm thinking I can do it with 
> Postscript drivers..... but first, the system....

>From what I know:

- PostScript does not return page count;

- and lpd would not collect the page count even if it was returned by

Now if you use PostScript encapsulated into PCL, the PCL outside job
can return page count.

And to be accurate, you must deny any user to access the printer
directly (setting access lit on the printer).

Ecapsulation in Perl:

# before the job
    print S "ESC%-12345X\@PJL JOB NAME=\"$ID_STRING\"\r\n";
    print S "\@PJL USTATUS JOB=ON\r\n";
    print S "\@PJL SET DUPLEX=ON\r\n";
# you PostScript or PCL file goes here\
# after the job
    print S "ESC%-12345X\@PJL EOJ NAME=\"$ID_STRING\"\r\n";
    print S "ESC%-12345X\r\n";

The ID_STRING is what you see fit, I use: 
    $ID_STRING="PID=$$ USER=$user HOST=$host";

With such encapsulation, the printer will return something like:

    my $end=0;
    my $job=0;
    while (<S>) {
        $end=1 if $_ =~ /^END/;
        $job=1 if $end && $_ =~ /^NAME=\"$ID_STRING\"/;
        $pages=$1 if $end && $job && $_ =~ /^PAGES=(\d+)/;

As you see, you can encapsulate PCL inside PCL too. And you can force
some default arguments in your outside PCL job (like print double
side) that will be true unless the user specify otherwise.

The above has been working fine with several HP printers over the


More information about the freebsd-questions mailing list