Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!uakari.primate.wisc.edu!gem.mps.ohio-state.edu!apple!sun-barr!newstop!sun!imagen!daemon From: geof@apolling (Geof Cooper) Newsgroups: comp.lang.postscript Subject: Re: How do you count the number of pages in a postscript document? Message-ID: <4551@imagen.UUCP> Date: 17 Oct 89 21:27:40 GMT Sender: daemon@imagen.UUCP Lines: 67 In article <1955@cunixc.cc.columbia.edu> seth@cunixc.cc.columbia.edu (Seth Strumph) writes: >does anyone have (or know of) a program that will count the number of >printed pages that an arbitrary postscript file (including those >created on a macintosh) will generate? I'll bite. The code below purports to do this function. It may cause some poorly written programs to loop infinitely, if they assume that showpage or copypage is an operator in a recursive call in a bound procedure. Otherwise will probably work fine. Many PostScript printers maintain a count of the number of pages ever printed on them in NOVRAM. It strikes me that checking this count is more effective that what I did. - Geof -----------------------CUT HERE--------------------------- %! % % Exitserver module that redefines showpage and copypage to % be procedures that count the number of pages processed since % it was loaded. % % The code makes use of the known "bug" in existing implementations % of PostScript whereby contents of strings are not restored by the % "restore" operator. % % % Minimally Tested. Released to Public Domain with no guarantees. % - Geof Cooper, QMS/IMAGEN % 0 serverdict /exitserver get exec userdict begin /_cnt 4 string def /_storeCount { dup 255 and //_cnt 0 3 2 roll put dup -8 bitshift 255 and //_cnt 1 3 2 roll put dup -16 bitshift 255 and //_cnt 2 3 2 roll put -24 bitshift 255 and //_cnt 3 3 2 roll put } bind def /_getCount { //_cnt 3 get 24 bitshift //_cnt 2 get 16 bitshift or //_cnt 1 get 8 bitshift or //_cnt 0 get or } bind def /_rshowpage /showpage load def /_rcopypage /copypage load def end /showpage { _getCount #copies add _storeCount _rshowpage } bind store /copypage { _getCount #copies add _storeCount _rcopypage } bind store