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

luo@dutepp1.et.tudelft.nl (Jian Luo) (05/31/91)

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.

Somebody has developed such a utility?  For example, this should work like:
ps2ps -f5 -t10 input.file, output.file
which will put the pages 5 to 10 to the output file (Postscript too).

Hope somebody could help me.  Or point me out where I can get such a utility?

Thanks in advance.

JIAN
<jian@hdetud11.bitnet>

--
===========================================================================
|| J. Luo                             |*| jian@hdetud11.bitnet           ||
|| Faculty of Electrical Engineering  |*| jluo@dutepp1.tudelft.nl        ||
|| Delft University of Technology     |*| Tel: +31-15-786227             ||

woody@chinacat.unicom.com (Woody Baker @ Eagle Signal) (06/02/91)

In article <.675678144@dutepp1> luo@dutepp1.et.tudelft.nl (Jian Luo) writes:
>
>Somebody has developed such a utility?  For example, this should work like:
>ps2ps -f5 -t10 input.file, output.file
>which will put the pages 5 to 10 to the output file (Postscript too).

As has been pointed out numerous times, this is more than just a trivial
problem.  Since keywords can be redefined, and aliases created for them,
it becomes almost impossible to determine where a page ends.  The best solution
to this problem, is an analysis of the output file, looking through the prolog
for the end of page command that it uses.  (create a couple of single line
pages) and then once you have found that, find the start of the page code
the same way.  Then write a routine to scan the file, locating the start of
page and end of page to isolate each page.  be sure and emit the preamble.
I recently did this for a company here in town for the INTERLEAF package
running on a sun workstation.  They needed to take the output from interleaf
and create a file stream that had the pages rearranged such that they
would print 2 up on both sides of a sheet (using a KODAK high speed
PS printer) such that when the pages were collated, and staped they would
create a neat booklet.  It took about 16 hours of hacking and work to get it
perfect, but it surely works fine for them.  The code is however, specific
to the interleaf software.

That is the surest way to accomplish this.  A good shell script programmer, 
using standard unix tools such as grep and awk should be able to create
a shell script to do this, again for a specific package.  Personally,
I have been toying with the idea of making a general routine that would
read a data file to retrieve lines of data, and use it to parse out
pages.  the file would contain the start of preamble line, the end of 
preamble line, the start of page line and the end of page line.  That way
one could just create this file, and bingo, you have one of these for
any given application package.

Cheers
Woody
p.s.  I HAVE NOT written this, and am a tad to busy to do so. 

mzellers@starnet.uucp (Mark Zellers) (06/06/91)

In article <1991Jun2.051004.11517@chinacat.unicom.com> woody@chinacat.unicom.com (Woody Baker @ Eagle Signal) writes:
>In article <.675678144@dutepp1> luo@dutepp1.et.tudelft.nl (Jian Luo) writes:
>>
>>Somebody has developed such a utility?  For example, this should work like:
>>ps2ps -f5 -t10 input.file, output.file
>>which will put the pages 5 to 10 to the output file (Postscript too).
>
>As has been pointed out numerous times, this is more than just a trivial
>problem.  Since keywords can be redefined, and aliases created for them,
>it becomes almost impossible to determine where a page ends.  The best solution
>to this problem, is an analysis of the output file, looking through the prolog
>for the end of page command that it uses.  (create a couple of single line
>pages) and then once you have found that, find the start of the page code
>the same way.  Then write a routine to scan the file, locating the start of
>page and end of page to isolate each page.  

There is another alternative, which might be a bit simpler.  What you
could do is redefine the "showpage" operator such that it would be
disabled except when printing certain pages.  Of course, you might have
problems if the file contained the showpage command within the scope of
a bind operator.  One solution to that would be a simple SED script that
would change all the showpages -> newshowpage and define newshowpage
appropriately.  As for keeping track of the current page number (without
getting hosed by the file's saves and restores, you could perhaps keep
it at the very bottom of the stack (provided the PostScript file you are
printing does not do evil things like clear the stack and whatnot).

Of course, things are even easier if the file is EPS, since there should
be page markers embedded in the file in the form of structuring
comments.

Mark H. Zellers
marc.com!bwayne!mark

ken@csis.dit.csiro.au (Ken Yap) (06/14/91)

This is very dependent on the PS generating program, but I have success
with EPS documents.  The structure looks like

	%!
	prolog
	%%Page: NNN
	page
	%%Page: NNN+1
	page
	...

So I just use sed to REMOVE the portions I DON'T WANT to print. The prolog
must be left intact.

By the way I wish toolkit distributors wouldn't send out multi-megabyte
PS files. I only had to do this sort of trick because the job kept
jamming every 20 or 30 pages. A PS file per chapter would have made
life easier and other users in the queue less upset.