Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!adobe!heaven!glenn From: glenn@heaven.woodside.ca.us (Glenn Reid) Newsgroups: comp.lang.postscript Subject: Re: PostScript page counter? Message-ID: <228@heaven.woodside.ca.us> Date: 2 Aug 90 04:36:40 GMT References: <1990Jul30.181713.29483@phri.nyu.edu> <6988@helios.TAMU.EDU> <226@heaven.woodside.ca.us> <1990Aug1.214448.17881@sq.sq.com> Reply-To: glenn@heaven.UUCP (Glenn Reid) Organization: Skyline Press, Woodside CA Lines: 60 In article <1990Aug1.214448.17881@sq.sq.com> lee@sq.sq.com (Liam R. E. Quin) writes: >Glenn Reid writes: >>I have a feeling there is a midway-point between the "you can't count >>pages without an interpreter" answer and the "just look at the %%Pages >>comment" answers [...] >and then suggests writing a simple parser to look for "showpage". >Some problems with that: >* you'd have to count copypage as well, of course >* you'd also have to take #copies into account (rather harder) >* what about > 1 NCopies 1 { copypage } repeat erasepage > produced by applications whose programmers didn't know about #copies...? >The original poster wanted to prevent students printing large jobs, >presumably either accidentally or intentionally. The former case can be >met in most cases by looking for %%Page and #copies. Hmmm. If the problem is multiple copies of the same page, then the scheme that I proposed won't do much good, admittedly. I doubt that that comes up very often, but I defer to those who actually needed the page counter to begin with :-) >Perhaps a better way would be to redefine showpage and copypage in the >printer at the start of each job to cause an error after MAX$JOB pages. > /oldshowpage { showpage } load bind etc def > /showpage { > NumberOfPages LotsAndLots gt > { please ignore to EOF } > { oldshowpage } > ifelse > } This is a good approach, but suffers from all the same defects (it doesn't pay attention to "copypage" and "#copies", for example). It can also be fairly easily defeated by anybody who cares to do so, with "systemdict /showpage get exec". The advantage of the parser running on the host computer is that you get to decide whether or not to print it at all. For example, the aforementioned "simple parser" could simply REJECT jobs that contained "copypage" or "#copies" anywhere in the body of the document, on the grounds that they aren't necessary and they may be malicious. I liked the awk script that Saumen Dutta posted.... Anyway, I still think that counting instances of "showpage" will work on a large percentage of the world's documents, and the program can be made more and more paranoid and careful as desired. /Glenn P.S. While we're at it, what a great idea it would be to put a filter into "lpd" that rejects any PostScript file that contains "systemdict", "erasepage", "72 mul", "#copies" or "Courier" :-) -- Glenn Reid PostScript/NeXT consultant glenn@heaven.woodside.ca.us Independent Software Developer ..{adobe,next}!heaven!glenn 415-851-1785