[comp.lang.postscript] "Take out" a position of a PS file

gfreeman@csadfa.cs.adfa.oz.au (Graham Freeman) (06/04/91)

luo@dutepp1.et.tudelft.nl (Jian Luo) writes:
>Sometimes I get a Postscript file which consists of many pages.  To some of the
>reasons, I need only print some of the pages.  So a utility which can "take out"
>these pages will do my work.

The way I solve this problem is to prepend the following PostScript
to my PostScript file before despatch to the printer.  It redefines
the "showpage" operator to count the occurrences of "showpage" calls,
and calls "erasepage" if the current page number is less than the
"PagLow", the starting page.  Stopping when the page number exceeds
"PagHi" is more difficult, as PostScript does not have an operator
for clean termination of execution.  "exit" would work only if the
"showpage" were not embedded in some type of loop.  I use "stop",
which may generate an error page after the requested pages, depending
on what type of error handler is installed in the machine.

This solution does not consider the page numbers within the document
itself (if they do not commence at one or are in reverse order), and
does not consider applications where "showpage" is already redefined
to give multiple pages per output page.

To use it, I edit the numbers associated with /PagHi and /PagLow
at the start, and send it ahead of the file to be printed.

                                              Graham Freeman
-------------------------Cut here-----------------------------------

%!
            % Only print pages in the selected page range
/PagLow 2 def
/PagHi 4 def

/oldshowpage /showpage load def
/showpage
 {
    0 begin /PageNo PageNo 1 add def 
    PageNo PagLow lt {erasepage}{oldshowpage}ifelse
    PageNo PagHi ge {stop} if
    end
 }bind def
/showpage load 0 1 dict dup /PageNo 0 put put