[comp.lang.postscript] Counting pages to be used by PostScript document

inei@dcs.glasgow.ac.uk (Nick Nei) (04/03/91)

This question has probably been asked before, but I am not a regular
reader of this group.

"Is it possible to count the number of pages BEFORE a postscript file
is printed?"

I know I can count AFTER the file is printed if I am using a LaserWriter.
But I am using the Sparc printer and the command:

	statusdict begin pagecount (*) print ==

makes NeWSPrint tell porkie pies.  It always says printed 1 page!

(Please reply by e-mail if possible.)
-- 
Mail:  Nick Nei, Computing Science Dept.,
       Glasgow Univ., 17 Lilybank Gardens,
       Glasgow G12 8QQ, UK.  Tel: (041) 339 8855 x 5457
ARPA:  inei%uk.ac.glasgow.dcs@nsfnet-relay.ac.uk USENET: inei@cs.glasgow.uucp

rberlin@birdlandEng.Sun.COM (Rich Berlin) (04/04/91)

In article <1991Apr3.012910.14781@dcs.glasgow.ac.uk>, inei@dcs.glasgow.ac.uk (Nick Nei) writes:
|> This question has probably been asked before, but I am not a regular
|> reader of this group.
|> 
|> "Is it possible to count the number of pages BEFORE a postscript file
|> is printed?"
|> 
|> I know I can count AFTER the file is printed if I am using a LaserWriter.
|> But I am using the Sparc printer and the command:
|> 
|> 	statusdict begin pagecount (*) print ==
|> 
|> makes NeWSPrint tell porkie pies.  It always says printed 1 page!
|> 
|> (Please reply by e-mail if possible.)
|> -- 
|> Mail:  Nick Nei, Computing Science Dept.,
|>        Glasgow Univ., 17 Lilybank Gardens,
|>        Glasgow G12 8QQ, UK.  Tel: (041) 339 8855 x 5457
|> ARPA:  inei%uk.ac.glasgow.dcs@nsfnet-relay.ac.uk USENET: inei@cs.glasgow.uucp

Sorry, there is no reliable way to count the pages that a job will
print without executing the PostScript.  If you have a PostScript
interpreter handy, you could try something like

%!
3 dict begin
    /_numpages 0 def
    /showpage {/_numpages _numpages #copies add store} bind def
    /copypage /showpage load def
    nulldevice
    userdict begin
        (your-filename-here) run
    end 
end
_numpages print


----

Many printers don't keep a record of how many pages they've printed.
There is no GENERAL way to get page counts, either before OR after the
document is printed, because there's no guarantee that statusdict
exists, or that it implements pagecount.  From the PostScript Language
Reference Manual, Second Edition, page 526:

    statusdict contains product-dependent operators and other data
    whose names and values vary from product to product, and sometimes
    from one version of a product to another.

    ...    

    statusdict is not necessarily defined in all products.  Any
    reference to statusdict in a POSTSCRIPT language program impairs
    the portability of that program.


If the particular engine maintains a pagecount in hardware, and
there's a way to query that value across the wire, pagecount could
probably be implemented for that printer.  I'll check on whether it's
possible for the SPARCprinter.

-- Rich