[comp.laser-printers] Counting pages on a HPLJ II

matt@EECS.NWU.EDU (Matt Larson) (04/17/91)

I am interested in writing a filter that can count the number of pages
printed to an HPLJ II.  The input stream could be plain text or the HP
graphics language.  Counting pages of text is easy; counting pages of
graphics (for example, output from Ghostscript, gnuplot, dvijep, etc.)
is the part that has me stumped.

Is there a sequence that always means, ``End of the page; print it''?
I thought that's what the formfeed character (ASCII 12) did.  I tried
counting formfeed characters, but that doesn't seem to work: there are
way too many.  My current guess is that the formfeed character really
means what I think it means, but that it is also possible for
formfeeds to be part of other commands or in some sort of "quoted
string."  If I am on the right track, then the question is: How do I
tell the real formfeeds that mean end of page from the other ones?

I have tried looking through the manual, but it doesn't seem to be
specific enough.  If anyone has done this or knows how to do it, I
would appreciate the help.

Thanks a lot,

Matt Larson
--
Matt Larson, Distributed Systems Analyst
Academic Computing and Network Services, Northwestern University
matt@acns.nwu.edu   (708) 491-5366

jcmorris@MWUNIX.MITRE.ORG (Joe Morris) (04/18/91)

matt@EECS.NWU.EDU (Matt Larson) writes:

>I am interested in writing a filter that can count the number of pages
>printed to an HPLJ II.  The input stream could be plain text or the HP
>graphics language.  Counting pages of text is easy; counting pages of
>graphics (for example, output from Ghostscript, gnuplot, dvijep, etc.)
>is the part that has me stumped.

>Is there a sequence that always means, ``End of the page; print it''?
>I thought that's what the formfeed character (ASCII 12) did.  I tried
>counting formfeed characters, but that doesn't seem to work: there are
>way too many.  My current guess is that the formfeed character really
>means what I think it means, but that it is also possible for
>formfeeds to be part of other commands or in some sort of "quoted
>string."  If I am on the right track, then the question is: How do I
>tell the real formfeeds that mean end of page from the other ones?

You're right; FF is the all-done-now-print order, but only if it is
received in a protocol context.  The bit pattern (x'0C') can also appear
in any of a number of binary data fields, either for graphic images
or in a font download.

I suspect that you'll have to write code to parse all of the PCL sequences
in much the same manner that VT-100 emulators have to parse its escape
sequences, even if you don't do anything with them.  I don't have the
book handy, but there are many PCL sequences of the form:

  <ESC> <operation> <character count> <binary data>

which you'll have to recognize and skip over without testing for the
presence of a form-feed command.

Joe Morris

henry@ZOO.TORONTO.EDU (Henry Spencer) (04/18/91)

In article <9104171649.AA25809@crayola.cs.UMD.EDU> matt@EECS.NWU.EDU (Matt Larson) writes:
>I am interested in writing a filter that can count the number of pages
>printed to an HPLJ II...
>Is there a sequence that always means, ``End of the page; print it''?

No.  In general, counting pages on a LaserJet is a royal pain.  Even for
text it is not simple, because things like changing the printer's line
spacing change how much text gets put on a single page.  You have to
essentially implement an interpreter for HP-PCL.

>... My current guess is that the formfeed character really
>means what I think it means, but that it is also possible for
>formfeeds to be part of other commands or in some sort of "quoted
>string."

Correct; *any* binary data can show up in graphics sequences.  You really
have to understand the escape sequences to follow the structure of the
document.
-- 
And the bean-counter replied,           | Henry Spencer @ U of Toronto Zoology
"beans are more important".             |  henry@zoo.toronto.edu  utzoo!henry

andrea@SDD.HP.COM (Andrea K. Frankel) (04/19/91)

In article <9104171649.AA25809@crayola.cs.UMD.EDU> matt@EECS.NWU.EDU (Matt Larson) writes:
>Is there a sequence that always means, ``End of the page; print it''?
>I thought that's what the formfeed character (ASCII 12) did.  I tried
>counting formfeed characters, but that doesn't seem to work: there are
>way too many.  My current guess is that the formfeed character really
>means what I think it means, but that it is also possible for
>formfeeds to be part of other commands or in some sort of "quoted
>string."  If I am on the right track, then the question is: How do I
>tell the real formfeeds that mean end of page from the other ones?

You will have to put together a mini escape-sequence parser.  Graphics
commands such as <esc>*b#W write a block of raster data out (the #
stands for the numeric parameter specifying how many bytes of data
follow).  Anything that looks like a formfeed that is part of raster
data should obviously not count as a page end!

Also, the sequence <esc>E (reset PCL command) will close and print
a page IF there was anything on it.  It's possible that the last page
in a multipage file might not end with a formfeed if they're using
<esc>E.

Information on all of this is in the Technical Reference Manual that
comes with your printer.  If you don't have one, get one!

Disclaimer:  I use LaserJets, I don't write their code ;@)

Andrea Frankel, Hewlett Packard, San Diego Technical Graphics Div., R&D Lab
	"wake now!  Discover that you are the song that the morning brings..."
______________________________________________________________________________
Internet : andrea@sdd.hp.com (or andrea%hp-sdd@nosc.mil or @ucsd.edu)
UUCP     : {hplabs|nosc|hpfcla|ucsd}!hp-sdd!andrea 
CSNET    : andrea%hp-sdd@hplabs.csnet
USnail   : 16399 W. Bernardo Drive - Mailstop 61U65, San Diego CA 92127-1899
Voice    : (619) 592-4664

zlsiirk@manchester-computing-centre.ac.uk ("R. E. Kruz.") (04/19/91)

This is my first posting so I hope I get through OK.

We have a similar request here at Manchester and I've come to the same
problem.Help on this would be appreciated.

The HP lasetjet manual and HP have told me that the number of pages
printed is stored in the printer but that there is no way to access it.
The only way to see it is to print the test page.  Does anyone out there 
know any method of getting this info into the workstation.
We are running Version 7.0 of HP-UX  on HP9000 s340 workstations.

Thanks in advance
Rick Kruze. 

jcmorris@MWUNIX.MITRE.ORG (Joe Morris) (04/20/91)

andrea@SDD.HP.COM (Andrea K. Frankel) writes:

>In article <9104171649.AA25809@crayola.cs.UMD.EDU> matt@EECS.NWU.EDU (Matt Larson) writes:
>>  [question about counting pages on an HP LJII]

>Information on all of this is in the Technical Reference Manual that
>comes with your printer.  If you don't have one, get one!

The book which comes with the printer is the user's guide, not the tech
reference manual.  The UG contains (to my surprise) a complete *list* of
the general structure of the PCL commands, but it doesn't explain their
use or interpretation.  That data is in the Tech Reference manual, which
you can order from H-P directly.  The price is only slightly exhorbitant,
but at least the call is free.  Call WATS information to get the number.

Joe Morris

tony@SDD.HP.COM (Tony Parkhurst) (04/20/91)

In article <9104171649.AA25809@crayola.cs.UMD.EDU>, matt@EECS.NWU.EDU (Matt Larson) writes:
|> I am interested in writing a filter that can count the number of pages
|> printed to an HPLJ II.  The input stream could be plain text or the HP
|> graphics language.  Counting pages of text is easy; counting pages of
|> graphics (for example, output from Ghostscript, gnuplot, dvijep, etc.)
|> is the part that has me stumped.


What's this worth to you?  :-)

Basically, write a general purpose PCL parser (does nothing but pass
thru data).  I did this the other day, took me about an hour or two.
You need to pass thru graphics and download data so they don't get 
interpreted as something else.

Next, decide what needs to be kept track of:

	1)  FF  (formfeeds are easy).
	2)  LF  (but you have to know how many to the page, which can be
		 changed by various escape sequences).
	3)  CR  (if the line termination is changed from default)
	4)  <esc>E  (reset, finishes and ejects a page, but only if it
		     gets printed on).
	5)  CAP moves, which don't go to a new page, but may set the
	    CAP to a lower position on the page which will mean less
	    LF's to get to the next page.

Seems like it should be a fun program to write.

-- Tony

henry@ZOO.TORONTO.EDU (Henry Spencer) (04/21/91)

In article <9104191550.AA03531@crayola.cs.UMD.EDU> zlsiirk@manchester-computing-centre.ac.uk ("R. E. Kruz.") writes:
>The HP lasetjet manual and HP have told me that the number of pages
>printed is stored in the printer but that there is no way to access it.
>The only way to see it is to print the test page.  Does anyone out there 
>know any method of getting this info into the workstation.

Can't be done.  The LaserJet *will not* send anything to the host except
control-S and control-Q for flow control.  There is no way to make it tell
you anything else.  HP's excuse for this is that LaserJets on parallel
ports have no return data path, and for some reason they feel that serial
ports have to be crippled to match.  (Caveat:  I haven't seen the manuals
for the very latest LaserJets yet.)
-- 
And the bean-counter replied,           | Henry Spencer @ U of Toronto Zoology
"beans are more important".             |  henry@zoo.toronto.edu  utzoo!henry