[comp.lang.postscript] page counting

thewalt@canuck.ce.berkeley.edu (C. Thewalt) (10/19/90)

Is there an easy way for me to find out the number of pages contained
in a PostScript file?  I don't want to believe the comments, and
showpage is often burried in some other macro, so how can this be done
easily?

Chris

--
Christopher Robin Thewalt               These opinions are not necessarily
thewalt@ce.berkeley.edu                 shared by my employer...
University of California, Berkeley

henry@zoo.toronto.edu (Henry Spencer) (10/21/90)

In article <THEWALT.90Oct19095522@canuck.ce.berkeley.edu> thewalt@canuck.ce.berkeley.edu (C. Thewalt) writes:
>Is there an easy way for me to find out the number of pages contained
>in a PostScript file?  I don't want to believe the comments, and
>showpage is often burried in some other macro, so how can this be done
>easily?

It can't be.  PostScript is too complex.

If you can't believe the comment, the only thing you can do is to run it
through a PostScript interpreter -- either in a printer or on your system --
and ask the interpreter to give you a page count.
-- 
The type syntax for C is essentially   | Henry Spencer at U of Toronto Zoology
unparsable.             --Rob Pike     |  henry@zoo.toronto.edu   utzoo!henry

shiva@well.sf.ca.us (Kenneth Porter) (11/02/90)

This subject comes up a lot and should be considered for the
FAQ list.  Perhaps pages can be accurately counted if you can
figure out how to read the engine's page counter.  This is the
counter that shows up on the start page along with the ROM
version and comm parameters.  Perhaps it's in statusdict or
printerdict.
 
Ken (shiva@well.sf.ca.us)

woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal) (11/04/90)

In article <21456@well.sf.ca.us>, shiva@well.sf.ca.us (Kenneth Porter) writes:
> 
> 
> figure out how to read the engine's page counter.  This is the
> counter that shows up on the start page along with the ROM
> version and comm parameters.  Perhaps it's in statusdict or
> printerdict.

Yes, you can read the counter.  But what most people want to do is to
compute the number of pages ahead of time.  The printer supplement 
for your particular printer will tell you how to do it, but there is an 
operator to do it.  You cannot, however reset it from within postscript
it's self.


Computing it ahead of time is something else.  Just counting showpages
or copypages won't necessarily work, as these can be fairly obscure.

Cheers
Woody 

rsmith@well.sf.ca.us (Ross Smith) (11/07/90)

In article <21456@well.sf.ca.us>, shiva@well.sf.ca.us (Kenneth Porter) writes:
> 
> 
> This subject comes up a lot and should be considered for the
> FAQ list.  Perhaps pages can be accurately counted if you can
> figure out how to read the engine's page counter.  This is the
> counter that shows up on the start page along with the ROM
> version and comm parameters.  Perhaps it's in statusdict or
> printerdict.
>  
> Ken (shiva@well.sf.ca.us)

The "pagecount" operator is defined in the Red Book.  But this
operator only counts the pages "after the fact".

I wrote the following program to count the number of pages in a 
PostScript file.  It seems to work fine with the files I threw at
it.  I hope this helps.

%!
% pagecnt.ps
% determine number of pages in a PostScript file

/_saveobj save def
/_pages 0 def
/_showpage /showpage load def
/showpage {
    /_pages _pages #copies add def
} def
/copypage /showpage load def

(filename.ps) run	% or include the file itself if your interpreter
                    % doesn't support the "run" operator

/Courier findfont 12 scalefont setfont
72 72 moveto
_pages 10 string cvs show
( total pages) show
_showpage
_saveobj restore

%%EOF
-- 
Ross Smith  rsmith@well.sf.ca.us   {apple,pacbell,hplabs,ucbvax}!well!rsmith