🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #5868

Re: printing a range of pages from a postscript file

#5868
From: Conrad Kimball
Date: Thu, 31 Dec 1992 08:27
124 lines
3927 bytes
In article <1h7flvINNjc1@tamsun.tamu.edu> vamsee@abgen.tamu.edu (Vamsee Lakamsani) writes:
> I have an 80 page postscript document and I need only pages 50-60,75,
> 78 and 80 (this is just a silly example). Is there someway that I can tell
> the printer to print only these pages?
>
> The printer is an Apple LaserWriter 2.
> We use "/usr/bin/lp". Is there some software for extracting only these 
> pages from the document ?

I use the following script that I got off the net some time ago.
--------------
#!/bin/sh

# Extracts a range of pages from a PostScript file, writing
# output to standard out.
#
# Synopsis:
#
# pssplit file first_page [ last_page ]
#
# If last_page is omitted, extracts from first_page to the end.
# To extract one page, make last_page the same as first_page.

if test $# -gt 2; then
    LAST=`expr $3 + 1`
else
    LAST=0
fi

sed -n -e "#
	   # first loop to copy all lines of the prolog
	   #
	   :prolog
	   1,/^%%EndProlog/{p
                            n
                            b prolog
                           }

	   # end of the prolog - now skip lines until we find the first
	   # page of the target range or a trailer.  if we encounter any
	   # included images we skip them entirely, without checking
	   # their contents

           :first
           /^%BeginIncludedImage/b includ1
           /^%%Page: [^ ][^ ]* $2\$/b pages
           /^%%Trailer/b trailr1
           n
           b first

	   # found an included image - skip until end of included image,
	   # then rejoin ordinary skip loop (above)

	   :includ1
           /^%EndIncludedImage/b first
	   n
	   b includ1

	   # found a trailer - loop to save lines in hold space until:
	   #
	   # 1. a new page (go back to "first" to skip more lines),
	   # 2. a "%!" line (go back to "first" to skip more lines),
	   # 3. end of file (print saved trailer).

           :trailr1
           /^%%Page: /b first
           /^%\!/b first
           H
           /^%%Trailer/h
           \${g
              p
             }
           n
           b trailr1

	   # found start of the target page range - copy lines until we
	   # find the end of the target page range

           :pages
           /^%%Page: [^ ][^ ]* $LAST\$/b skip
           p
           n
           b pages

	   # found end of the target page range - skip lines until we
	   # find the start of the trailer.  if we encounter any
	   # included images we skip them entirely, without checking
	   # their contents

           :skip
           /^%BeginIncludedImage/b includ1
           /^%%Trailer/b trailr2
           n
           b skip

	   # found an included image - skip until end of included image,
	   # then rejoin ordinary skip loop (above)

	   :includ2
           /^%EndIncludedImage/b skip
	   n
	   b includ2

	   # found a trailer - loop to save lines in hold space until:
	   #
	   # 1. a new page (go back to "skip" to skip more lines),
	   # 2. a "%!" line (go back to "skip" to skip more lines),
	   # 3. end of file (print saved trailer).

           :trailr2
           /^%%Page: /b skip
           /^%\!/b skip
           H
           /^%%Trailer/h
           \${g
              p
             }
           n
           b trailr2" $1
-- 
--
Conrad Kimball       | Client Server Tech Services, Boeing Computer Services
cek@sdc.boeing.com   | P.O. Box 24346, MS 7A-35
(206) 865-6410       | Seattle, WA  98124-0346
Technical Details
Message-ID: <7700@fury.BOEING.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!bcstec!bcsaic!sundry!sdc!cek
References: <1h7flvINNjc1@tamsun.tamu.edu> <id.ES1W.3M2@ferranti.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!bcstec!bcsaic!sundry!sdc!cek
From: cek@sdc.boeing.com (Conrad Kimball)
Newsgroups: comp.lang.postscript
Subject: Re: printing a range of pages from a postscript file
Message-ID: <7700@fury.BOEING.COM>
Date: 31 Dec 92 08:27:46 GMT
References: <1h7flvINNjc1@tamsun.tamu.edu> <id.ES1W.3M2@ferranti.com>
Organization: Boeing Computer Services (ESP), Seattle, WA
Lines: 124