[comp.lang.postscript] PS page counter

consult@physc1.byu.edu (11/09/89)

  I am looking for a (simple?) algorithm to count pages in a postscript
file.  I know almost nothing about postscript, so I am soliciting your
help here.
  For years we have been using a modified lpr program on our Unix systems
that counts the number of pages being printed and charges the user a set
rate for each page.  Our problem now is that users have access to laser
printers over the net and if they try to print postscript files they are
usually way overcharged, as there can be many more than 66 lines per page
with all the font and graphics information in a postscript file.
  What I would like to do is first detect if the file being printed is
postscript (I believe it must start with '%!', right?) and if it is use
the new formula for calculating the number of pages being printed.
  Thanks for your help.

  Cary Jamison
  BYU CS Dept. Systems Programmer
  cary@cs.byu.edu

roy@phri.UUCP (Roy Smith) (11/10/89)

	Unfortunately, the short answer is "you can't".  PostScript is a
real programming language with loops and functions.  One could, if they
wanted, write the PS version of "for = 1 to 1000000, print 'hello'" and
unless your printer accounting software had a full postscript interpreter
in it, there would be no way to know that this little 1-line print file
would produce thousands of pages of output.

	In practice, however, most programs which produce PS output are
fairly well behaved and produce "%%Page" comments at the appropriate places
in the PS file, and don't do any looping.  It would be straight-forward to
parse the file and look for those, but you would only be able to account
for usage by honest people using well-behaved programs.

-- 
Roy Smith, Public Health Research Institute
455 First Avenue, New York, NY 10016
{att,philabs,cmcl2,rutgers,hombre}!phri!roy -or- roy@alanine.phri.nyu.edu
"The connector is the network"

perry@ccssrv.UUCP (Perry Hutchison) (11/11/89)

In article <1consult@physc1.byu.edu> consult@physc1.byu.edu writes:

> I am looking for a (simple?) algorithm to count pages in a postscript file.

This is becoming a frequently-asked question in this group.

Trying to do this by inspection is a lot like trying to estimate the
size of a C program's output by examining the source code.  (PostScript
is very much a programming language.)  To do this reliably on the host
system, you would have to write a PostScript interpreter.

For accounting purposes (as opposed to setting print queue priority based
on job size), an after-the-fact count may be acceptable.  It has the
advantages of being relatively simple to implement and also fairly secure.

The LaserWriter (and presumably most other PostScript printers) have a
host-readable counter which shows how many pages have ever been printed by
this printer.  You can read that counter before and after each job, and
charge accordingly.

mongo@helios (Mongo Package) (11/12/89)

Responding to an article asking how to count how many pages were printed
by a PostScript printer...
In article <4108@phri.UUCP> roy@phri.UUCP (Roy Smith) writes:
>
>       Unfortunately, the short answer is "you can't".  PostScript is a
>real programming language with loops and functions.  One could, if they
>wanted, write the PS version of "for = 1 to 1000000, print 'hello'" and
>unless your printer accounting software had a full postscript interpreter
>in it, there would be no way to know that this little 1-line print file
>would produce thousands of pages of output.
>
>Roy Smith, Public Health Research Institute
>"The connector is the network"

Here at Lick Observatory we not only account for the number of pages
printed, but also for the amount of LaserWriter cpu time necessary to do it.
This is accomplished by using a home-grown printer driver which sends out
the LaserWriter commands "pagecount" and "usertime" before and after each
job is transmitted.  It reads these back off the serial port and takes
the difference at the end.  We then charge the print requestor for both
pages and cpu time.

(Disclaimer--I personally consider accounting for cpu to be particularly
abhorrent, but the UC _loves_ bureaucracy and _especially_loves_ to give
people pieces of paper that say "You owe us $$$".)

Steve Allen
mongo@helios.ucsc.edu           Internet
mongo@portal                    BITNET
...!ucbvax!ucscc!helios!mongo   UUCP